feat: simplify code project creation

This commit is contained in:
inman
2026-09-07 10:06:37 +08:00
parent f8eee430f4
commit af13aca003
15 changed files with 351 additions and 486 deletions

View File

@@ -174,6 +174,36 @@ describe('coding project durable identity', () => {
expect((await projects.getConfig(local.project.id)).config.projectId).toBe(PROJECT_ID);
});
it('automatically assigns one identity when a legacy project is read concurrently', async () => {
const projectPath = await makeRoot();
const store = makeStore();
const local = await createLocalCodingProject({ projectPath, now: CREATED }, store);
const createProjectId = vi.fn(() => PROJECT_ID);
const events: string[] = [];
const projects = new CodingProjectService(store, {
createProjectId,
now: () => UPDATED,
onProjectIdentityChanging: () => { events.push('invalidate'); },
writeConfig: async (filePath, value) => {
events.push('write');
await writeCodingProjectConfigV2(filePath, value);
},
onResourcesChanged: () => { events.push('resources'); },
});
const [first, second] = await Promise.all([
projects.getConfig(local.project.id),
projects.getConfig(local.project.id),
]);
expect(first.config.projectId).toBe(PROJECT_ID);
expect(second.config.projectId).toBe(PROJECT_ID);
expect(createProjectId).toHaveBeenCalledTimes(1);
expect(events).toEqual(['invalidate', 'write', 'resources']);
await expect(readCodingProjectConfigV2(projectPath))
.resolves.toMatchObject({ status: 'valid', config: { projectId: PROJECT_ID, updatedAt: UPDATED } });
});
it('keeps ordinary saves immutable and supports a confirmed independent copy', async () => {
const projectPath = await makeRoot();
const store = makeStore();
@@ -280,8 +310,13 @@ describe('coding project durable identity', () => {
const legacyPath = await makeRoot('makelore-project-identity-legacy-');
const legacyStore = makeStore();
await createLocalCodingProject({ projectPath: legacyPath }, legacyStore);
await expect(new CodingProjectService(legacyStore).requireActiveRealProjectWithIdentity())
.rejects.toMatchObject({ code: 'CODING_PROJECT_IDENTITY_REQUIRED', status: 409 });
const legacyProjects = new CodingProjectService(legacyStore, {
createProjectId: () => NEXT_PROJECT_ID,
});
await expect(legacyProjects.requireActiveRealProjectWithIdentity())
.resolves.toMatchObject({ projectId: NEXT_PROJECT_ID });
await expect(readCodingProjectConfigV2(legacyPath))
.resolves.toMatchObject({ status: 'valid', config: { projectId: NEXT_PROJECT_ID } });
});
it('exposes identity resolution and independent-copy through the Host routes', async () => {