refactor(artifacts): reconcile workspace artifacts at completion

This commit is contained in:
ZacharyZhang-NY committed 2026-04-24 00:58:07 -04:00
1 parent 2ddc67cc3d
commit fd86fc6668
17 files changed
+114 -436

No files matched your search

+16 -7
View File
@@ -9,7 +9,7 @@ function createRpc(response: { ok: true; result: unknown } | { ok: false; error:
}
describe("agent hook RPC policy", () => {
it("fails afterToolCall when main cannot acknowledge artifact projection", async () => {
it("fails beforeToolCall closed when main cannot answer approval policy", async () => {
const rpc = createRpc({ ok: false, error: "RuntimeBridge unavailable" });
const hooks = buildAgentHooks({
runId: "11111111-1111-4111-8111-111111111111",
@@ -17,12 +17,21 @@ describe("agent hook RPC policy", () => {
});
await expect(
hooks.afterToolCall({
toolCall: { name: "write", id: "tool-call-1" },
hooks.beforeToolCall({
toolCall: { name: "bash", id: "tool-call-1" },
args: { path: "report.md" },
result: { content: [], details: null },
isError: false,
} as unknown as Parameters<typeof hooks.afterToolCall>[0]),
).rejects.toThrow("afterToolCall RPC failed: RuntimeBridge unavailable");
} as unknown as Parameters<typeof hooks.beforeToolCall>[0]),
).rejects.toThrow("beforeToolCall RPC failed: RuntimeBridge unavailable");
});
it("installs no per-tool artifact projection hook", () => {
const rpc = createRpc({ ok: true, result: { block: false, reason: null } });
const hooks = buildAgentHooks({
runId: "11111111-1111-4111-8111-111111111111",
rpc,
});
expect(Object.keys(hooks).sort()).toEqual(["beforeToolCall", "transformContext"]);
expect("afterToolCall" in hooks).toBe(false);
});
});
+1 -48
View File
@@ -5,7 +5,6 @@ import { afterEach, describe, expect, it, vi } from "vitest";
import type { AppDatabase } from "../../src/main/database";
import {
captureBaselineIfRequired,
projectToolExecutionToWorkProduct,
reconcileWorkspaceArtifacts,
type ArtifactProjectorRunContext,
} from "../../src/main/agent-runtime/artifact-projector";
@@ -46,47 +45,7 @@ describe("artifact projector error taxonomy", () => {
expect(logger.error).not.toHaveBeenCalled();
});
it("classifies missing filesystem artifact projection failures", async () => {
const logger = createLogger();
const workspacePath = await createTempDir("agentcompany-artifact-errors-");
const absPath = join(workspacePath, "missing.md");
const ctx: ArtifactProjectorRunContext = {
runId: "run-artifact-error",
agentId: "agent-artifact-error",
companyId: "company-artifact-error",
taskId: "task-artifact-error",
workspaceId: "workspace-artifact-error",
workspacePath,
workspaceMode: "exclusive",
logger,
workspaceBaseline: null,
};
const outcomes = projectToolExecutionToWorkProduct(
{} as AppDatabase,
ctx,
{
toolName: "write",
args: { path: "missing.md" },
result: null,
isError: false,
},
);
expect(outcomes).toEqual([{ kind: "skipped", reason: "path_missing" }]);
expect(logger.warn).toHaveBeenCalledWith(
"[artifact.fs.path_stat_failed] Failed to stat filesystem artifact before projection.",
{
workspacePath,
absPath,
runId: "run-artifact-error",
},
expect.stringContaining("cause="),
);
expect(logger.error).not.toHaveBeenCalled();
});
it("skips broad bash projection when the run has no change source", async () => {
it("skips completion reconciliation when the run has no change source", async () => {
const workspacePath = await createTempDir("agentcompany-shared-artifacts-");
const ctx: ArtifactProjectorRunContext = {
runId: "run-shared",
@@ -100,12 +59,6 @@ describe("artifact projector error taxonomy", () => {
workspaceBaseline: null,
};
expect(projectToolExecutionToWorkProduct({} as AppDatabase, ctx, {
toolName: "bash",
args: { command: "touch report.md" },
result: null,
isError: false,
})).toEqual([{ kind: "skipped", reason: "no_baseline" }]);
expect(reconcileWorkspaceArtifacts({} as AppDatabase, ctx)).toEqual([
{ kind: "skipped", reason: "no_baseline" },
]);