Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions src/artifacts/register-artifact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,12 +339,6 @@ export async function registerArtifact(
}
}

const metadataInitiativeId =
typeof metadata.initiative_id === "string" && metadata.initiative_id.trim().length > 0
? metadata.initiative_id.trim()
: null;
const initiativeIdHint = input.entity_type === "initiative" ? input.entity_id : metadataInitiativeId;

let entity: any = null;
let created = false;
let usedLegacyCreate = false;
Expand All @@ -363,7 +357,6 @@ export async function registerArtifact(
preview_markdown: input.preview_markdown ?? undefined,
status,
metadata,
...(initiativeIdHint ? { initiative_id: initiativeIdHint } : {}),
...createdBy,
});

Expand All @@ -389,7 +382,6 @@ export async function registerArtifact(
confidence_score: confidenceScore ?? undefined,
entity_type: input.entity_type,
entity_id: input.entity_id,
...(initiativeIdHint ? { initiative_id: initiativeIdHint } : {}),
artifact_url: artifactUrl,
status,
metadata,
Expand All @@ -410,7 +402,6 @@ export async function registerArtifact(
confidence_score: confidenceScore ?? undefined,
entity_type: input.entity_type,
entity_id: input.entity_id,
...(initiativeIdHint ? { initiative_id: initiativeIdHint } : {}),
artifact_url: artifactUrl,
status,
metadata,
Expand Down
52 changes: 52 additions & 0 deletions tests/artifacts/register-artifact-client-contract.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,58 @@ test("registerArtifact sends confidence_score via metadata for client contract c
assert.equal(createCall.body.metadata.confidence_score, 0.67);
});

test("registerArtifact keeps initiative context in metadata and off the top-level artifact payload", async () => {
const artifactId = "12121212-1212-4212-8212-121212121212";
const entityId = "34343434-3434-4434-8434-343434343434";
const baseUrl = "https://www.useorgx.com";
const calls = [];

const client = {
getUserId: () => "",
rawRequest: async (method, path, body) => {
calls.push({ method, path, body });
if (method === "POST" && path === "/api/client/artifacts") {
return {
ok: true,
artifact: {
id: artifactId,
artifact_url: `${baseUrl}/artifacts/${artifactId}`,
entity_type: "initiative",
entity_id: entityId,
},
};
}
throw new Error(`Unexpected request: ${method} ${path}`);
},
createEntity: async () => {
throw new Error("createEntity should not be called");
},
updateEntity: async () => {
throw new Error("updateEntity should not be called");
},
};

const result = await registerArtifact(client, baseUrl, {
entity_type: "initiative",
entity_id: entityId,
name: "Initiative Scoped Artifact",
artifact_type: "shared.project_handbook",
description: "Ensure initiative scope stays in metadata only.",
external_url: "https://example.com/artifacts/init-scope",
metadata: {
initiative_id: entityId,
workstream_id: "ws-1",
},
});

assert.equal(result.ok, true);
const createCall = calls.find((call) => call.method === "POST" && call.path === "/api/client/artifacts");
assert.ok(createCall);
assert.equal(Object.hasOwn(createCall.body, "initiative_id"), false);
assert.equal(createCall.body.metadata.initiative_id, entityId);
assert.equal(createCall.body.metadata.workstream_id, "ws-1");
});

test("validateRegisterArtifactInput rejects unknown entity_type values", () => {
const errors = validateRegisterArtifactInput({
entity_type: "artifact",
Expand Down
2 changes: 1 addition & 1 deletion tests/http/autopilot-slice-lifecycle.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ test("autopilot slice lifecycle: success registers artifact and completes run",
assert.ok(artifactCreate, "expected artifact.create");
assert.equal(artifactCreate.payload?.entity_type, "initiative");
assert.equal(artifactCreate.payload?.entity_id, "init-1");
assert.equal(artifactCreate.payload?.initiative_id, "init-1");
assert.equal(Object.hasOwn(artifactCreate.payload ?? {}, "initiative_id"), false);
assert.equal(artifactCreate.payload?.name, "Mock deliverable");
assert.equal(artifactCreate.payload?.artifact_type, "document");
assert.equal(artifactCreate.payload?.created_by_type, "human");
Expand Down
Loading