Files
AgentCompany/tests/unit/knowledge-provenance.test.ts
T
ZacharyZhang-NY b772e1c758 Build the current workspace snapshot on native CI runners
This branch snapshots the in-progress desktop workspace so GitHub-hosted Windows and Linux runners can package the same source tree that already passes local verification on macOS.

Constraint: Local Apple Silicon Docker/Wine packaging crashes before Windows artifacts are produced
Rejected: Publish from the incomplete base repo state | remote typecheck failed because current source additions were missing
Confidence: medium
Scope-risk: broad
Directive: Treat this branch as a build snapshot only; do not merge it without reviewing the unrelated workspace changes it contains
Tested: local typecheck, lint, workspace typecheck, unit tests, integration tests, e2e smoke, macOS signed release upload
Not-tested: Native Windows/Linux artifacts before this CI run
2026-04-04 03:28:14 -04:00

60 lines
1.8 KiB
TypeScript

import { mkdtemp, rm } from "node:fs/promises";
import { join } from "node:path";
import { tmpdir } from "node:os";
import { afterEach, describe, expect, it } from "vitest";
import { AppDatabase } from "../../src/main/database";
const tempDirs: string[] = [];
async function createTempDir(prefix: string) {
const dir = await mkdtemp(join(tmpdir(), prefix));
tempDirs.push(dir);
return dir;
}
afterEach(async () => {
await Promise.all(tempDirs.splice(0).map((dir) => rm(dir, { recursive: true, force: true })));
});
describe("knowledge provenance", () => {
it("preserves or refreshes sourceRunId when an existing knowledge entry is updated", async () => {
const profileDir = await createTempDir("agentcompany-knowledge-provenance-");
const db = new AppDatabase(profileDir);
db.init();
const companyId = db.saveCompany({
name: "Knowledge Provenance Co",
description: "Tests sourceRunId updates on knowledge entry edits",
status: "active",
});
const knowledgeId = db.saveKnowledgeEntry({
companyId,
category: "lesson_learned",
topic: "Original lesson",
content: "Initial content",
importance: "medium",
sourceRunId: null,
});
db.saveKnowledgeEntry({
id: knowledgeId,
companyId,
category: "lesson_learned",
topic: "Original lesson",
content: "Updated content with better guidance",
importance: "high",
sourceRunId: "run-123",
});
const entry = db.queryAll<{ sourceRunId: string | null; importance: string }>(
"select source_run_id as sourceRunId, importance from knowledge_base where id = ? limit 1",
knowledgeId,
)[0];
expect(entry?.sourceRunId).toBe("run-123");
expect(entry?.importance).toBe("high");
db.close();
});
});