FN-5695: sync feature assertions for late-added mission features

Close the assertion-graph gap by making mission feature assertions store-managed and automatically synchronized.

- add `sourceFeatureId` to contract assertions (types, schema migration, persistence, snapshot restore)
- auto-create/update/delete managed assertions when features are added, edited, or removed in `MissionStore`
- remove duplicate/manual assertion creation from mission routes and rely on centralized store behavior
- expand core, dashboard, engine, and plugin tests plus docs to cover validator behavior for later-added features

Files changed:
 docs/missions.md                                   | 11 ++-
 docs/storage.md                                    |  2 +-
 packages/core/src/__tests__/db-migrate.test.ts     | 12 ++--
 packages/core/src/__tests__/db.test.ts             | 34 ++++-----
 packages/core/src/__tests__/goals-schema.test.ts   |  2 +-
 packages/core/src/__tests__/insight-store.test.ts  | 10 +--
 packages/core/src/__tests__/mission-store.test.ts  | 82 +++++++++++++++++++---
 packages/core/src/__tests__/run-audit.test.ts      |  2 +-
 packages/core/src/__tests__/secrets-schema.test.ts |  6 +-
 .../core/src/__tests__/store-merge-queue.test.ts   |  2 +-
 packages/core/src/__tests__/task-documents.test.ts |  2 +-
 packages/core/src/db.ts                            | 11 ++-
 packages/core/src/mission-store.ts                 | 69 ++++++++++++++++--
 packages/core/src/mission-types.ts                 |  4 ++
 .../dashboard/src/__tests__/mission-e2e.test.ts    | 70 ++++++++++++------
 packages/dashboard/src/mission-routes.ts           | 16 +----
 .../src/__tests__/mission-execution-loop.test.ts   | 46 +++++++++++-
 .../src/store/__tests__/roadmap-store.test.ts      |  4 +-
 18 files changed, 288 insertions(+), 97 deletions(-)

Fusion-Task-Id: FN-5695
Fusion-Task-Lineage: 337f030c-e883-41aa-b982-13ebe45bd5ee
This commit is contained in:
gsxdsm
2026-05-29 13:19:51 -07:00
parent c5d03ae9de
commit bac12d1e28
18 changed files with 288 additions and 97 deletions

View File

@@ -715,7 +715,7 @@ describe("schema migration", () => {
const row = db.prepare("SELECT deletedAt FROM tasks WHERE id = 'FN-legacy'").get() as { deletedAt: string | null };
expect(row.deletedAt).toBeNull();
expect(db.getSchemaVersion()).toBe(96);
expect(db.getSchemaVersion()).toBe(97);
db.close();
});
@@ -748,7 +748,7 @@ describe("schema migration", () => {
{ id: "WS-001", mode: "prompt", gateMode: "advisory" },
{ id: "WS-002", mode: "script", gateMode: "advisory" },
]);
expect(db.getSchemaVersion()).toBe(96);
expect(db.getSchemaVersion()).toBe(97);
db.close();
});
@@ -798,7 +798,7 @@ describe("schema migration", () => {
reviewerContextRetryCount: 0,
reviewerFallbackRetryCount: 0,
});
expect(db.getSchemaVersion()).toBe(96);
expect(db.getSchemaVersion()).toBe(97);
db.close();
});
@@ -827,7 +827,7 @@ describe("schema migration", () => {
const columns = db.prepare("PRAGMA table_info(milestones)").all() as Array<{ name: string }>;
expect(columns.map((column) => column.name)).toContain("acceptanceCriteria");
expect(db.getSchemaVersion()).toBe(96);
expect(db.getSchemaVersion()).toBe(97);
db.close();
});
@@ -868,7 +868,7 @@ describe("schema migration", () => {
const missionColumns = db.prepare("PRAGMA table_info(missions)").all() as Array<{ name: string }>;
expect(missionColumns.map((column) => column.name)).toContain("autoMerge");
expect(db.getSchemaVersion()).toBe(96);
expect(db.getSchemaVersion()).toBe(97);
db.close();
});
@@ -902,7 +902,7 @@ describe("schema migration", () => {
{ id: "WS-002", mode: "script", enabled: 1, gateMode: "advisory" },
{ id: "WS-003", mode: "prompt", enabled: 0, gateMode: "advisory" },
]);
expect(db.getSchemaVersion()).toBe(96);
expect(db.getSchemaVersion()).toBe(97);
db.close();
});

View File

@@ -330,7 +330,7 @@ describe("Database", () => {
});
it("seeds schema version", () => {
expect(db.getSchemaVersion()).toBe(96);
expect(db.getSchemaVersion()).toBe(97);
});
it("includes tokenUsageCacheWriteTokens on freshly initialized tasks table", () => {
@@ -389,7 +389,7 @@ describe("Database", () => {
it("is idempotent - calling init() twice does not fail", () => {
expect(() => db.init()).not.toThrow();
expect(db.getSchemaVersion()).toBe(96);
expect(db.getSchemaVersion()).toBe(97);
});
it("does not overwrite existing config on re-init", () => {
// Update the config
@@ -1459,7 +1459,7 @@ describe("schema migrations", () => {
db.init();
// Verify version bumped to 29 (includes v1→v2 through v26→v29)
expect(db.getSchemaVersion()).toBe(96);
expect(db.getSchemaVersion()).toBe(97);
// Verify new columns exist and existing data is intact
const cols = db.prepare("PRAGMA table_info(tasks)").all() as Array<{ name: string }>;
@@ -1484,11 +1484,11 @@ describe("schema migrations", () => {
const db = new Database(fusionDir);
db.init();
expect(db.getSchemaVersion()).toBe(96);
expect(db.getSchemaVersion()).toBe(97);
// Re-init should not fail
db.init();
expect(db.getSchemaVersion()).toBe(96);
expect(db.getSchemaVersion()).toBe(97);
db.close();
});
@@ -1523,7 +1523,7 @@ describe("schema migrations", () => {
db.init();
expect(db.getSchemaVersion()).toBe(96);
expect(db.getSchemaVersion()).toBe(97);
const cols = db.prepare("PRAGMA table_info(tasks)").all() as Array<{ name: string }>;
expect(cols.map((col) => col.name)).toContain("priority");
@@ -1564,7 +1564,7 @@ describe("schema migrations", () => {
db.init();
expect(db.getSchemaVersion()).toBe(96);
expect(db.getSchemaVersion()).toBe(97);
const cols = db.prepare("PRAGMA table_info(tasks)").all() as Array<{ name: string }>;
const colNames = cols.map((col) => col.name);
@@ -1636,7 +1636,7 @@ describe("schema migrations", () => {
db.init();
expect(db.getSchemaVersion()).toBe(96);
expect(db.getSchemaVersion()).toBe(97);
const cols = db.prepare("PRAGMA table_info(tasks)").all() as Array<{ name: string }>;
const colNames = cols.map((col) => col.name);
@@ -1876,7 +1876,7 @@ describe("schema migrations", () => {
db.init();
expect(db.getSchemaVersion()).toBe(96);
expect(db.getSchemaVersion()).toBe(97);
const cols = db.prepare("PRAGMA table_info(chat_messages)").all() as Array<{ name: string }>;
expect(cols.map((col) => col.name)).toContain("attachments");
@@ -1950,7 +1950,7 @@ describe("schema migrations", () => {
db.init();
expect(db.getSchemaVersion()).toBe(96);
expect(db.getSchemaVersion()).toBe(97);
const tables = db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name = 'agentRatings'").all() as Array<{ name: string }>;
expect(tables).toEqual([{ name: "agentRatings" }]);
@@ -1974,7 +1974,7 @@ describe("schema migrations", () => {
db.init();
expect(db.getSchemaVersion()).toBe(96);
expect(db.getSchemaVersion()).toBe(97);
const tables = db.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name = 'mission_events'").all() as Array<{ name: string }>;
expect(tables).toEqual([{ name: "mission_events" }]);
@@ -2078,7 +2078,7 @@ describe("schema migrations", () => {
db.init();
// Verify version bumped to 29
expect(db.getSchemaVersion()).toBe(96);
expect(db.getSchemaVersion()).toBe(97);
// Verify new columns exist and existing data is intact
const cols = db.prepare("PRAGMA table_info(tasks)").all() as Array<{ name: string }>;
@@ -2297,7 +2297,7 @@ describe("schema migrations", () => {
localDb.init();
expect(localDb.getSchemaVersion()).toBe(96);
expect(localDb.getSchemaVersion()).toBe(97);
const columns = localDb.prepare("PRAGMA table_info(tasks)").all() as Array<{ name: string }>;
expect(columns.map((column) => column.name)).toContain("tokenUsageCacheWriteTokens");
@@ -2608,7 +2608,7 @@ describe("createDatabase factory", () => {
const db = createDatabase(fusionDir);
db.init();
expect(db.getSchemaVersion()).toBe(96);
expect(db.getSchemaVersion()).toBe(97);
expect(db.getLastModified()).toBeGreaterThan(0);
db.close();
@@ -2762,7 +2762,7 @@ describe("migration v77 task token budget columns", () => {
migrated = new Database(fusion);
migrated.init();
expect(migrated.getSchemaVersion()).toBe(96);
expect(migrated.getSchemaVersion()).toBe(97);
const rows = migrated.prepare("PRAGMA table_info(tasks)").all() as Array<{ name: string }>;
const names = new Set(rows.map((row) => row.name));
expect(names.has("tokenBudgetSoftAlertedAt")).toBe(true);
@@ -2808,7 +2808,7 @@ describe("migration v67 drops orphan project auth tables", () => {
migrated = new Database(fusion);
migrated.init();
expect(migrated.getSchemaVersion()).toBe(96);
expect(migrated.getSchemaVersion()).toBe(97);
const tables = migrated
.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name LIKE 'project_auth_%'")
.all() as Array<{ name: string }>;
@@ -2835,7 +2835,7 @@ describe("migration v67 drops orphan project auth tables", () => {
try {
fresh.init();
expect(fresh.getSchemaVersion()).toBe(96);
expect(fresh.getSchemaVersion()).toBe(97);
const tables = fresh
.prepare("SELECT name FROM sqlite_master WHERE type='table' AND name LIKE 'project_auth_%'")
.all() as Array<{ name: string }>;

View File

@@ -91,6 +91,6 @@ describe("goals schema", () => {
});
it("reports schema version 92", () => {
expect(db.getSchemaVersion()).toBe(96);
expect(db.getSchemaVersion()).toBe(97);
});
});

View File

@@ -1000,7 +1000,7 @@ describe("Migration: pre-33 DB upgrade", () => {
// Step 1: Create a fresh database at v33 (runs all migrations up to 33)
const db1 = createDatabase(legacyDir);
db1.init();
expect(db1.getSchemaVersion()).toBe(96);
expect(db1.getSchemaVersion()).toBe(97);
db1.close();
// Step 2: Manually downgrade to version 32 and drop insight tables
@@ -1035,7 +1035,7 @@ describe("Migration: pre-33 DB upgrade", () => {
expect(tableNamesBefore).not.toContain("project_insight_runs");
// Now run init — this triggers the v32→v33 migration
db3.init();
expect(db3.getSchemaVersion()).toBe(96);
expect(db3.getSchemaVersion()).toBe(97);
// Step 4: Verify insight tables exist after migration
const tablesAfter = db3.prepare(
@@ -1066,12 +1066,12 @@ describe("Migration: pre-33 DB upgrade", () => {
try {
const db1 = createDatabase(testDir);
db1.init();
expect(db1.getSchemaVersion()).toBe(96);
expect(db1.getSchemaVersion()).toBe(97);
db1.close();
const db2 = createDatabase(testDir);
expect(() => db2.init()).not.toThrow();
expect(db2.getSchemaVersion()).toBe(96);
expect(db2.getSchemaVersion()).toBe(97);
db2.close();
} finally {
rmSync(testDir, { recursive: true, force: true });
@@ -1085,7 +1085,7 @@ describe("Migration: pre-33 DB upgrade", () => {
// Step 1: Create a fresh DB and run migrations
const db1 = createDatabase(compatDir);
db1.init();
expect(db1.getSchemaVersion()).toBe(96);
expect(db1.getSchemaVersion()).toBe(97);
// Step 2: Strip lifecycle and cancelledAt columns by recreating the
// table without them. This simulates a DB that was created before the

View File

@@ -2577,8 +2577,8 @@ describe("MissionStore", () => {
store.linkFeatureToAssertion(feature.id, assertion.id);
const linkedAssertions = store.listAssertionsForFeature(feature.id);
expect(linkedAssertions).toHaveLength(1);
expect(linkedAssertions[0].id).toBe(assertion.id);
expect(linkedAssertions).toHaveLength(2);
expect(linkedAssertions.some((a) => a.id === assertion.id)).toBe(true);
});
it("lists assertions for a feature", () => {
@@ -2589,8 +2589,8 @@ describe("MissionStore", () => {
store.linkFeatureToAssertion(feature.id, a2.id);
const linked = store.listAssertionsForFeature(feature.id);
expect(linked).toHaveLength(2);
expect(linked.map((a) => a.title).sort()).toEqual(["A1", "A2"]);
expect(linked).toHaveLength(3);
expect(linked.map((a) => a.title)).toEqual(expect.arrayContaining(["A1", "A2"]));
});
it("lists features for an assertion", () => {
@@ -2610,7 +2610,8 @@ describe("MissionStore", () => {
store.unlinkFeatureFromAssertion(feature.id, assertion.id);
const linked = store.listAssertionsForFeature(feature.id);
expect(linked).toHaveLength(0);
expect(linked).toHaveLength(1);
expect(linked[0].sourceFeatureId).toBe(feature.id);
});
it("throws when linking already-linked feature-assertion pair", () => {
@@ -2718,7 +2719,7 @@ describe("MissionStore", () => {
const rollup = store.getMilestoneValidationRollup(milestone.id);
expect(rollup.totalAssertions).toBe(2);
expect(rollup.totalAssertions).toBe(3);
expect(rollup.passedAssertions).toBe(1);
expect(rollup.unlinkedAssertions).toBe(0);
expect(rollup.state).toBe("ready");
@@ -2728,11 +2729,13 @@ describe("MissionStore", () => {
const slice = store.addSlice(milestone.id, { title: "Slice" });
const feature = store.addFeature(slice.id, { title: "Feature" });
const [managed] = store.listAssertionsForFeature(feature.id);
const a1 = store.addContractAssertion(milestone.id, { title: "A1", assertion: "T" });
const a2 = store.addContractAssertion(milestone.id, { title: "A2", assertion: "T" });
store.linkFeatureToAssertion(feature.id, a1.id);
store.linkFeatureToAssertion(feature.id, a2.id);
store.updateContractAssertion(managed.id, { status: "passed" });
store.updateContractAssertion(a1.id, { status: "passed" });
store.updateContractAssertion(a2.id, { status: "passed" });
@@ -2790,7 +2793,8 @@ describe("MissionStore", () => {
// Link all assertions
const slice = store.addSlice(milestone.id, { title: "Slice" });
const feature = store.addFeature(slice.id, { title: "Feature" });
const assertions = store.listContractAssertions(milestone.id);
const assertions = store.listContractAssertions(milestone.id)
.filter((a) => a.sourceFeatureId !== feature.id);
for (const a of assertions) {
store.linkFeatureToAssertion(feature.id, a.id);
}
@@ -2872,6 +2876,10 @@ describe("MissionStore", () => {
const slice = store.addSlice(milestone.id, { title: "Slice" });
const feature = store.addFeature(slice.id, { title: "Feature" });
const managed = store.listAssertionsForFeature(feature.id);
expect(managed).toHaveLength(1);
store.unlinkFeatureFromAssertion(feature.id, managed[0].id);
// Create assertions but don't link them
store.addContractAssertion(milestone.id, { title: "A1", assertion: "T" });
@@ -2882,11 +2890,69 @@ describe("MissionStore", () => {
});
});
describe("Feature assertion canonical seam", () => {
it("creates exactly one managed assertion with acceptance criteria text", () => {
const mission = store.createMission({ title: "M" });
const milestone = store.addMilestone(mission.id, { title: "MS" });
const slice = store.addSlice(milestone.id, { title: "SL" });
const feature = store.addFeature(slice.id, { title: "Feature", acceptanceCriteria: "AC text" });
const linked = store.listAssertionsForFeature(feature.id);
expect(linked).toHaveLength(1);
expect(linked[0].assertion).toBe("AC text");
expect(linked[0].sourceFeatureId).toBe(feature.id);
});
it("derives managed assertion text from description or fallback", () => {
const mission = store.createMission({ title: "M" });
const milestone = store.addMilestone(mission.id, { title: "MS" });
const slice = store.addSlice(milestone.id, { title: "SL" });
const fromDescription = store.addFeature(slice.id, { title: "Desc Feature", description: "Desc text" });
const fallback = store.addFeature(slice.id, { title: "Fallback Feature" });
expect(store.listAssertionsForFeature(fromDescription.id)[0].assertion).toBe("Desc text");
expect(store.listAssertionsForFeature(fallback.id)[0].assertion).toBe("Verify implementation of: Fallback Feature");
});
it("syncs managed assertion in place on acceptanceCriteria update", () => {
const mission = store.createMission({ title: "M" });
const milestone = store.addMilestone(mission.id, { title: "MS" });
const slice = store.addSlice(milestone.id, { title: "SL" });
const feature = store.addFeature(slice.id, { title: "Feature", acceptanceCriteria: "Old" });
const before = store.listAssertionsForFeature(feature.id)[0];
store.updateFeature(feature.id, { acceptanceCriteria: "New" });
const after = store.listAssertionsForFeature(feature.id);
expect(after).toHaveLength(1);
expect(after[0].id).toBe(before.id);
expect(after[0].assertion).toBe("New");
});
it("does not change managed assertion on status-only update", () => {
const mission = store.createMission({ title: "M" });
const milestone = store.addMilestone(mission.id, { title: "MS" });
const slice = store.addSlice(milestone.id, { title: "SL" });
const feature = store.addFeature(slice.id, { title: "Feature" });
const before = store.listAssertionsForFeature(feature.id)[0];
store.updateFeature(feature.id, { status: "triaged" });
const after = store.listAssertionsForFeature(feature.id)[0];
expect(after.id).toBe(before.id);
expect(after.updatedAt).toBe(before.updatedAt);
});
it("removes managed assertion row on feature delete", () => {
const mission = store.createMission({ title: "M" });
const milestone = store.addMilestone(mission.id, { title: "MS" });
const slice = store.addSlice(milestone.id, { title: "SL" });
const feature = store.addFeature(slice.id, { title: "Feature" });
const assertionId = store.listAssertionsForFeature(feature.id)[0].id;
store.deleteFeature(feature.id);
expect(store.getContractAssertion(assertionId)).toBeUndefined();
});
});
// ── Loop State & Validator Run Schema Tests ───────────────────────────
describe("Loop State & Validator Run Schema (v31)", () => {
it("schema version is 40 after migration", () => {
expect(db.getSchemaVersion()).toBe(96);
expect(db.getSchemaVersion()).toBe(97);
});
it("mission_features table has loop state columns", () => {

View File

@@ -584,7 +584,7 @@ describe("Run Audit", () => {
});
it("schema version is bumped to 40", () => {
expect(db.getSchemaVersion()).toBe(96);
expect(db.getSchemaVersion()).toBe(97);
});
});
});

View File

@@ -42,7 +42,7 @@ describe("secrets schema migrations", () => {
const version = db
.prepare("SELECT value FROM __meta WHERE key = 'schemaVersion'")
.get() as { value: string };
expect(version.value).toBe("96");
expect(version.value).toBe("97");
} finally {
db.close();
rmSync(dir, { recursive: true, force: true });
@@ -105,7 +105,7 @@ describe("secrets schema migrations", () => {
const version = db
.prepare("SELECT value FROM __meta WHERE key = 'schemaVersion'")
.get() as { value: string };
expect(version.value).toBe("96");
expect(version.value).toBe("97");
} finally {
db.close();
rmSync(dir, { recursive: true, force: true });
@@ -155,7 +155,7 @@ describe("secrets schema migrations", () => {
.prepare("SELECT value FROM __meta WHERE key = 'schemaVersion'")
.get() as { value: string };
expect(projectVersion.value).toBe("96");
expect(projectVersion.value).toBe("97");
expect(centralVersion.value).toBe("13");
} finally {
projectDb.close();

View File

@@ -60,7 +60,7 @@ describe("TaskStore merge queue", () => {
expect.arrayContaining(["idx_mergeQueue_lease_ready", "idx_mergeQueue_leaseExpiresAt"]),
);
expect(store.getDatabase().getSchemaVersion()).toBe(96);
expect(store.getDatabase().getSchemaVersion()).toBe(97);
});
it("migrates a legacy v88 database and preserves task rows", async () => {

View File

@@ -51,7 +51,7 @@ describe("TaskStore task documents", () => {
expect(tableNames.has("task_documents")).toBe(true);
expect(tableNames.has("task_document_revisions")).toBe(true);
expect(db.getSchemaVersion()).toBe(96);
expect(db.getSchemaVersion()).toBe(97);
const index = db
.prepare(

View File

@@ -149,7 +149,7 @@ export function probeFts5(db: DatabaseSync): boolean {
// ── Schema Definition ────────────────────────────────────────────────
const SCHEMA_VERSION = 96;
const SCHEMA_VERSION = 97;
function normalizeTaskComments(
steeringComments: SteeringComment[] | undefined,
@@ -1176,6 +1176,7 @@ export const MIGRATION_ONLY_TABLE_SCHEMAS: Record<string, Record<string, string>
assertion: "TEXT NOT NULL",
status: "TEXT NOT NULL DEFAULT 'pending'",
orderIndex: "INTEGER NOT NULL DEFAULT 0",
sourceFeatureId: "TEXT",
createdAt: "TEXT NOT NULL",
updatedAt: "TEXT NOT NULL",
},
@@ -3710,6 +3711,14 @@ export class Database {
});
}
if (version < 97) {
this.applyMigration(97, () => {
if (this.hasTable("mission_contract_assertions")) {
this.addColumnIfMissing("mission_contract_assertions", "sourceFeatureId", "TEXT");
}
});
}
}
/**

View File

@@ -203,6 +203,7 @@ interface AssertionRow {
assertion: string;
status: string;
orderIndex: number;
sourceFeatureId: string | null;
createdAt: string;
updatedAt: string;
}
@@ -380,6 +381,7 @@ export class MissionStore extends EventEmitter<MissionStoreEvents> {
return {
id: row.id,
milestoneId: row.milestoneId,
sourceFeatureId: row.sourceFeatureId || undefined,
title: row.title,
assertion: row.assertion,
status: row.status as import("./mission-types.js").MissionAssertionStatus,
@@ -1724,8 +1726,9 @@ export class MissionStore extends EventEmitter<MissionStoreEvents> {
// here ensures the full chain is updated atomically when a feature is added.
this.recomputeSliceStatus(sliceId);
this.applyDerivedMilestoneAcceptanceCriteria(slice.milestoneId);
this.ensureFeatureAssertion(feature);
return feature;
return this.getFeature(feature.id) ?? feature;
}
/**
@@ -1819,6 +1822,14 @@ export class MissionStore extends EventEmitter<MissionStoreEvents> {
this.recomputeSliceStatus(updated.sliceId);
}
const shouldSyncAssertion = updates.title !== undefined
|| updates.description !== undefined
|| updates.acceptanceCriteria !== undefined;
if (shouldSyncAssertion) {
this.ensureFeatureAssertion(updated);
return this.getFeature(updated.id) ?? updated;
}
return updated;
}
@@ -1835,6 +1846,15 @@ export class MissionStore extends EventEmitter<MissionStoreEvents> {
}
const sliceId = feature.sliceId;
const slice = this.getSlice(sliceId);
const milestoneId = slice?.milestoneId;
if (milestoneId) {
const managedAssertion = this.listContractAssertions(milestoneId)
.find((assertion) => assertion.sourceFeatureId === feature.id);
if (managedAssertion) {
this.deleteContractAssertion(managedAssertion.id);
}
}
this.db.prepare("DELETE FROM mission_features WHERE id = ?").run(id);
this.db.bumpLastModified();
@@ -1845,6 +1865,39 @@ export class MissionStore extends EventEmitter<MissionStoreEvents> {
this.recomputeSliceStatus(sliceId);
}
private ensureFeatureAssertion(feature: MissionFeature): void {
const slice = this.getSlice(feature.sliceId);
if (!slice) {
throw new Error(`Slice ${feature.sliceId} not found`);
}
const milestoneId = slice.milestoneId;
const assertionText = feature.acceptanceCriteria?.trim()
|| feature.description?.trim()
|| `Verify implementation of: ${feature.title}`;
const existing = this.listContractAssertions(milestoneId)
.find((assertion) => assertion.sourceFeatureId === feature.id);
if (!existing) {
const created = this.addContractAssertion(milestoneId, {
title: feature.title,
assertion: assertionText,
status: "pending",
sourceFeatureId: feature.id,
});
this.linkFeatureToAssertion(feature.id, created.id);
return;
}
if (existing.title !== feature.title || existing.assertion !== assertionText) {
this.updateContractAssertion(existing.id, {
title: feature.title,
assertion: assertionText,
});
}
}
/**
* Resolve the mission hierarchy for a slice.
*
@@ -2584,6 +2637,7 @@ export class MissionStore extends EventEmitter<MissionStoreEvents> {
const assertion: MissionContractAssertion = {
id,
milestoneId,
sourceFeatureId: input.sourceFeatureId,
title: input.title,
assertion: input.assertion,
status: input.status || "pending",
@@ -2593,8 +2647,8 @@ export class MissionStore extends EventEmitter<MissionStoreEvents> {
};
this.db.prepare(`
INSERT INTO mission_contract_assertions (id, milestoneId, title, assertion, status, orderIndex, createdAt, updatedAt)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
INSERT INTO mission_contract_assertions (id, milestoneId, title, assertion, status, orderIndex, sourceFeatureId, createdAt, updatedAt)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
`).run(
assertion.id,
assertion.milestoneId,
@@ -2602,6 +2656,7 @@ export class MissionStore extends EventEmitter<MissionStoreEvents> {
assertion.assertion,
assertion.status,
assertion.orderIndex,
assertion.sourceFeatureId ?? null,
assertion.createdAt,
assertion.updatedAt,
);
@@ -3485,10 +3540,10 @@ export class MissionStore extends EventEmitter<MissionStoreEvents> {
for (const assertion of snapshot.payload.assertions) {
if (!assertion.id || !assertion.milestoneId) continue;
this.db.prepare(`INSERT INTO mission_contract_assertions (id, milestoneId, title, assertion, status, orderIndex, createdAt, updatedAt)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
ON CONFLICT(id) DO UPDATE SET title=excluded.title, assertion=excluded.assertion, status=excluded.status, orderIndex=excluded.orderIndex, updatedAt=excluded.updatedAt`)
.run(assertion.id, assertion.milestoneId, assertion.title, assertion.assertion, assertion.status, assertion.orderIndex, assertion.createdAt, assertion.updatedAt);
this.db.prepare(`INSERT INTO mission_contract_assertions (id, milestoneId, title, assertion, status, orderIndex, sourceFeatureId, createdAt, updatedAt)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
ON CONFLICT(id) DO UPDATE SET title=excluded.title, assertion=excluded.assertion, status=excluded.status, orderIndex=excluded.orderIndex, sourceFeatureId=excluded.sourceFeatureId, updatedAt=excluded.updatedAt`)
.run(assertion.id, assertion.milestoneId, assertion.title, assertion.assertion, assertion.status, assertion.orderIndex, assertion.sourceFeatureId ?? null, assertion.createdAt, assertion.updatedAt);
}
for (const link of snapshot.payload.featureAssertionLinks) {

View File

@@ -556,6 +556,8 @@ export interface MissionContractAssertion {
id: string;
/** Parent milestone ID */
milestoneId: string;
/** Feature ID when this assertion is store-managed for a specific feature */
sourceFeatureId?: string;
/** Human-readable title describing the assertion */
title: string;
/** The behavioral specification or acceptance test content */
@@ -618,6 +620,8 @@ export interface ContractAssertionCreateInput {
assertion: string;
/** Initial status, defaults to "pending" */
status?: MissionAssertionStatus;
/** Feature ID when this assertion is store-managed for a specific feature */
sourceFeatureId?: string;
}
/**