fix: mine FK candidates from approved SQL joins in the acceptance

This commit is contained in:
2026-08-11 19:33:42 +02:00
parent c994b3ef68
commit 742c311660
+6 -3
View File
@@ -1163,9 +1163,12 @@ async function realChecks(ctx) {
{ {
id: "schema_review", id: "schema_review",
async run() { async run() {
// FK suggestion consumes the workspace's own introspected physical schema. // FK suggestion consumes the workspace's own introspected physical schema and mines
// approved SQL joins for candidates.
await runThothctlJson(ctx, "preprocess-dwh-filesystem", ["workspace", "preprocess", "dwh", "--workspace", "p2-filesystem"], 0); await runThothctlJson(ctx, "preprocess-dwh-filesystem", ["workspace", "preprocess", "dwh", "--workspace", "p2-filesystem"], 0);
const suggest = await runThothctlJson(ctx, "schema-suggest-filesystem", ["workspace", "schema", "suggest-fks", "--workspace", "p2-filesystem"], 3); const sqlPath = join(ctx.run.root, "fixtures", "p2-filesystem.sql");
await atomicWrite(sqlPath, "SELECT v.id FROM dw.visits v JOIN dw.patients p ON v.patient_id = p.id\n");
const suggest = await runThothctlJson(ctx, "schema-suggest-filesystem", ["workspace", "schema", "suggest-fks", "--workspace", "p2-filesystem", "--from-sql", sqlPath], 3);
assert(suggest.payload.code === "manual_review_required", "suggest did not block"); assert(suggest.payload.code === "manual_review_required", "suggest did not block");
assert(typeof suggest.payload.suggestedFksYaml === "string" && suggest.payload.suggestedFksYaml.length > 0, "suggested FK YAML missing"); assert(typeof suggest.payload.suggestedFksYaml === "string" && suggest.payload.suggestedFksYaml.length > 0, "suggested FK YAML missing");
const digest = suggest.payload.artifactIdentities?.[0]?.digest; const digest = suggest.payload.artifactIdentities?.[0]?.digest;
@@ -1182,7 +1185,7 @@ async function realChecks(ctx) {
], 0); ], 0);
assert(checked.payload.status === "succeeded", "schema check failed"); assert(checked.payload.status === "succeeded", "schema check failed");
state.filesystemCandidateDigest = digest; state.filesystemCandidateDigest = digest;
return { commands: ["thothctl"], artifacts: [...suggest.artifacts, ...checked.artifacts, await fileArtifact(ctx.run.root, "fixtures/p2-filesystem.candidates.yaml"), await fileArtifact(ctx.run.root, "fixtures/p2-filesystem.annotations.yaml")] }; return { commands: ["thothctl"], artifacts: [...suggest.artifacts, ...checked.artifacts, await fileArtifact(ctx.run.root, "fixtures/p2-filesystem.candidates.yaml"), await fileArtifact(ctx.run.root, "fixtures/p2-filesystem.annotations.yaml"), await fileArtifact(ctx.run.root, "fixtures/p2-filesystem.sql")] };
}, },
}, },
{ {