|
1 | 1 | import { beforeEach, expect, mock, test } from "bun:test"; |
2 | 2 |
|
| 3 | +import { HACK_PROJECT_DIR_PRIMARY } from "../src/constants.ts"; |
| 4 | +import type { ProjectView } from "../src/lib/project-views.ts"; |
| 5 | +import type { RegisteredProject } from "../src/lib/projects-registry.ts"; |
3 | 6 | import type { RuntimeProject } from "../src/lib/runtime-projects.ts"; |
4 | 7 |
|
5 | 8 | const runtimeQueue: Array<{ |
@@ -109,6 +112,79 @@ test("runtime cache refresh records healthy snapshot", async () => { |
109 | 112 | expect(autoRegisterCalls.length).toBe(1); |
110 | 113 | }); |
111 | 114 |
|
| 115 | +test("getProjectsPayload keeps working when resolveProjectMeta fails for one project", async () => { |
| 116 | + const createdAt = new Date().toISOString(); |
| 117 | + |
| 118 | + const projects: RegisteredProject[] = [ |
| 119 | + { |
| 120 | + id: "ok", |
| 121 | + name: "ok", |
| 122 | + repoRoot: "/tmp/ok", |
| 123 | + projectDirName: HACK_PROJECT_DIR_PRIMARY, |
| 124 | + projectDir: "/tmp/ok/.hack", |
| 125 | + createdAt, |
| 126 | + }, |
| 127 | + { |
| 128 | + id: "bad", |
| 129 | + name: "bad", |
| 130 | + repoRoot: "/tmp/bad", |
| 131 | + projectDirName: HACK_PROJECT_DIR_PRIMARY, |
| 132 | + projectDir: "/tmp/bad/.hack", |
| 133 | + createdAt, |
| 134 | + }, |
| 135 | + ]; |
| 136 | + |
| 137 | + const makeView = (name: string): ProjectView => ({ |
| 138 | + name, |
| 139 | + devHost: null, |
| 140 | + repoRoot: null, |
| 141 | + projectDir: null, |
| 142 | + definedServices: null, |
| 143 | + extensionsEnabled: null, |
| 144 | + features: null, |
| 145 | + serviceHosts: null, |
| 146 | + runtimeConfigured: null, |
| 147 | + runtimeStatus: "unknown", |
| 148 | + runtime: null, |
| 149 | + branchRuntime: [], |
| 150 | + kind: "registered", |
| 151 | + status: "unknown", |
| 152 | + }); |
| 153 | + |
| 154 | + const cache = createRuntimeCache({ |
| 155 | + deps: { |
| 156 | + readProjectsRegistry: async () => ({ version: 1, projects }), |
| 157 | + buildProjectViews: async () => [makeView("ok"), makeView("bad")], |
| 158 | + serializeProjectView: (view) => ({ name: view.name, kind: view.kind }), |
| 159 | + resolveProjectMeta: async (opts) => { |
| 160 | + if (opts.projectName === "bad") { |
| 161 | + throw new Error("boom"); |
| 162 | + } |
| 163 | + return { projectName: opts.projectName }; |
| 164 | + }, |
| 165 | + }, |
| 166 | + }); |
| 167 | + |
| 168 | + await cache.refresh({ reason: "test" }); |
| 169 | + |
| 170 | + const payload = await cache.getProjectsPayload({ |
| 171 | + filter: null, |
| 172 | + includeGlobal: true, |
| 173 | + includeUnregistered: true, |
| 174 | + includeMeta: true, |
| 175 | + }); |
| 176 | + |
| 177 | + expect(payload.projects.length).toBe(2); |
| 178 | + expect(payload.projects[0]).toMatchObject({ |
| 179 | + name: "ok", |
| 180 | + meta: { projectName: "ok" }, |
| 181 | + }); |
| 182 | + expect(payload.projects[1]).toMatchObject({ |
| 183 | + name: "bad", |
| 184 | + meta: null, |
| 185 | + }); |
| 186 | +}); |
| 187 | + |
112 | 188 | test("runtime cache retains last runtime on failure", async () => { |
113 | 189 | const runtime: RuntimeProject[] = [ |
114 | 190 | { |
|
0 commit comments