fix: complete Release A migration execution
This commit is contained in:
@@ -162,21 +162,35 @@ test("workspace artifact source verifies locator identity hash and size", async
|
||||
const snapshotPath = join(directory, "snapshot.json");
|
||||
const workspaceRoot = join(directory, "hwlab-v03");
|
||||
const stateDir = join(workspaceRoot, "web-observe", "run-1");
|
||||
const reportBytes = Buffer.from('{"ok":true}\n');
|
||||
const artifacts = [
|
||||
["analysis/report.json", Buffer.from('{"ok":true}\n')],
|
||||
["analysis/details.json", Buffer.from('{"details":true}\n')],
|
||||
["artifacts/request.txt", Buffer.from("request\n")],
|
||||
["artifacts/response.txt", Buffer.from("response\n")],
|
||||
["screenshots/page.png", Buffer.from([0x89, 0x50, 0x4e, 0x47])],
|
||||
] as const;
|
||||
const reportBytes = artifacts[0][1];
|
||||
mkdirSync(join(stateDir, "analysis"), { recursive: true });
|
||||
writeFileSync(join(stateDir, "analysis", "report.json"), reportBytes);
|
||||
for (const [relativePath, bytes] of artifacts) {
|
||||
const path = join(stateDir, relativePath);
|
||||
mkdirSync(join(path, ".."), { recursive: true });
|
||||
writeFileSync(path, bytes);
|
||||
}
|
||||
const reportHash = `sha256:${createHash("sha256").update(reportBytes).digest("hex")}`;
|
||||
const database = new Database(sqlitePath);
|
||||
database.run("CREATE TABLE runs (id TEXT, state_dir TEXT, artifact_owner_pvc TEXT, artifact_count INTEGER, report_json_sha256 TEXT, updated_at TEXT)");
|
||||
database.run("INSERT INTO runs VALUES (?, ?, ?, ?, ?, ?)", ["run-1", stateDir, "legacy-web-observe-workspace-nc01", 1, reportHash, "2026-07-12T00:00:00.000Z"]);
|
||||
database.run("CREATE TABLE runs (id TEXT, state_dir TEXT, artifact_count INTEGER, report_json_sha256 TEXT, updated_at TEXT)");
|
||||
database.run("INSERT INTO runs VALUES (?, ?, ?, ?, ?)", ["run-1", stateDir, 5, reportHash, "2026-07-12T00:00:00.000Z"]);
|
||||
database.close();
|
||||
const source = { sentinelId: "fixture", node: "NC01", lane: "v03", path: sqlitePath, runtimeConfigRef: "fixture#runtime", stateRoot: directory, ownerPvc: "fixture-pvc", artifactSources: [{ ownerPvc: "fixture-pvc", mountPath: directory }, { ownerPvc: "legacy-web-observe-workspace-nc01", mountPath: workspaceRoot, hostPath: workspaceRoot }] };
|
||||
const snapshot = exportMonitorSqliteSnapshot(source, snapshotPath);
|
||||
const store = createInMemoryMonitorCentralStore();
|
||||
await importMonitorSqliteSnapshot(snapshot, store);
|
||||
const run = await store.run({ sentinelId: "fixture", node: "NC01", lane: "v03" }, "run-1");
|
||||
assert.deepEqual(run?.artifactLocators, [{ ownerNode: "NC01", ownerLane: "v03", ownerPvc: "legacy-web-observe-workspace-nc01", stateDir, relativePath: "analysis/report.json", sha256: reportHash, sizeBytes: reportBytes.byteLength, kind: "report-json", reachable: true }]);
|
||||
assert.equal(run?.artifactLocators.length, 5);
|
||||
assert.deepEqual(run?.artifactLocators.map((locator) => ({ ownerPvc: locator.ownerPvc, stateDir: locator.stateDir, relativePath: locator.relativePath, sha256: locator.sha256, sizeBytes: locator.sizeBytes })), artifacts.map(([relativePath, bytes]) => ({ ownerPvc: "legacy-web-observe-workspace-nc01", stateDir, relativePath, sha256: `sha256:${createHash("sha256").update(bytes).digest("hex")}`, sizeBytes: bytes.byteLength })).sort((left, right) => left.relativePath.localeCompare(right.relativePath)));
|
||||
assert.equal((await verifyMonitorSqliteSnapshotAgainstStore(snapshot, store)).ok, true);
|
||||
rmSync(join(stateDir, "artifacts", "response.txt"));
|
||||
await assert.rejects(() => importMonitorSqliteSnapshot(snapshot, createInMemoryMonitorCentralStore()), (error: unknown) => { const migrationError = error as { code?: string; diagnostic?: Record<string, unknown> }; return migrationError.code === "monitor-migration-artifact-count-mismatch" && migrationError.diagnostic?.runId === "run-1" && migrationError.diagnostic?.stateDir === stateDir && migrationError.diagnostic?.expectedCount === 5 && migrationError.diagnostic?.observedCount === 4; });
|
||||
} finally {
|
||||
rmSync(directory, { recursive: true, force: true });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user