@paperclipai/shared 2026.1202.0 → 2026.1203.0-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/.paperclip-build-complete +1 -1
- package/dist/adapter-login.d.ts +6 -0
- package/dist/adapter-login.d.ts.map +1 -0
- package/dist/adapter-login.js +22 -0
- package/dist/adapter-login.js.map +1 -0
- package/dist/agent-configuration.d.ts +3 -0
- package/dist/agent-configuration.d.ts.map +1 -1
- package/dist/agent-runner.d.ts +4 -0
- package/dist/agent-runner.d.ts.map +1 -1
- package/dist/agent-runner.js +9 -7
- package/dist/agent-runner.js.map +1 -1
- package/dist/agent-setup-progress.d.ts +97 -0
- package/dist/agent-setup-progress.d.ts.map +1 -0
- package/dist/agent-setup-progress.js +47 -0
- package/dist/agent-setup-progress.js.map +1 -0
- package/dist/aggregator-app-catalog.d.ts +2 -0
- package/dist/aggregator-app-catalog.d.ts.map +1 -1
- package/dist/aggregator-app-catalog.js +4 -3
- package/dist/aggregator-app-catalog.js.map +1 -1
- package/dist/ai-connections.d.ts +5 -0
- package/dist/ai-connections.d.ts.map +1 -1
- package/dist/ai-connections.js +13 -0
- package/dist/ai-connections.js.map +1 -1
- package/dist/ai-provider-routing.d.ts.map +1 -1
- package/dist/ai-provider-routing.js +5 -1
- package/dist/ai-provider-routing.js.map +1 -1
- package/dist/antigravity-models.d.ts +63 -0
- package/dist/antigravity-models.d.ts.map +1 -0
- package/dist/antigravity-models.generated.d.ts +138 -0
- package/dist/antigravity-models.generated.d.ts.map +1 -0
- package/dist/antigravity-models.generated.js +211 -0
- package/dist/antigravity-models.generated.js.map +1 -0
- package/dist/antigravity-models.js +141 -0
- package/dist/antigravity-models.js.map +1 -0
- package/dist/antigravity-models.test.d.ts +2 -0
- package/dist/antigravity-models.test.d.ts.map +1 -0
- package/dist/antigravity-models.test.js +81 -0
- package/dist/antigravity-models.test.js.map +1 -0
- package/dist/app-definitions/anthropic.json +2 -2
- package/dist/app-definitions/{google.json → antigravity.json} +8 -8
- package/dist/app-definitions/asana.json +1 -0
- package/dist/app-definitions/aws.json +0 -1
- package/dist/app-definitions/google-workspace.json +2 -3
- package/dist/app-definitions/railway.json +2 -1
- package/dist/app-definitions/slack.json +3 -3
- package/dist/app-definitions/speko.json +2 -2
- package/dist/app-definitions.generated.js +1 -1
- package/dist/app-definitions.generated.js.map +1 -1
- package/dist/app-definitions.js +1 -1
- package/dist/app-definitions.js.map +1 -1
- package/dist/app-definitions.test.js +36 -3
- package/dist/app-definitions.test.js.map +1 -1
- package/dist/cloud-inference.d.ts +143 -0
- package/dist/cloud-inference.d.ts.map +1 -0
- package/dist/cloud-inference.js +175 -0
- package/dist/cloud-inference.js.map +1 -0
- package/dist/connector-availability.d.ts.map +1 -1
- package/dist/connector-availability.js +1 -3
- package/dist/connector-availability.js.map +1 -1
- package/dist/connector-availability.test.js +3 -0
- package/dist/connector-availability.test.js.map +1 -1
- package/dist/constants.d.ts +16 -3
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +23 -0
- package/dist/constants.js.map +1 -1
- package/dist/customer-success.d.ts +76 -1
- package/dist/customer-success.d.ts.map +1 -1
- package/dist/customer-success.js +118 -3
- package/dist/customer-success.js.map +1 -1
- package/dist/environment-support.d.ts +31 -2
- package/dist/environment-support.d.ts.map +1 -1
- package/dist/environment-support.js +40 -2
- package/dist/environment-support.js.map +1 -1
- package/dist/environment-support.test.js +51 -7
- package/dist/environment-support.test.js.map +1 -1
- package/dist/feature-catalog.d.ts.map +1 -1
- package/dist/feature-catalog.js +22 -8
- package/dist/feature-catalog.js.map +1 -1
- package/dist/google-sign-in-deployment.d.ts +7 -0
- package/dist/google-sign-in-deployment.d.ts.map +1 -0
- package/dist/google-sign-in-deployment.js +12 -0
- package/dist/google-sign-in-deployment.js.map +1 -0
- package/dist/google-sign-in-deployment.test.d.ts +2 -0
- package/dist/google-sign-in-deployment.test.d.ts.map +1 -0
- package/dist/google-sign-in-deployment.test.js +33 -0
- package/dist/google-sign-in-deployment.test.js.map +1 -0
- package/dist/google-workspace-connectors.d.ts +4 -0
- package/dist/google-workspace-connectors.d.ts.map +1 -1
- package/dist/google-workspace-connectors.js +33 -0
- package/dist/google-workspace-connectors.js.map +1 -1
- package/dist/google-workspace-connectors.test.js +19 -3
- package/dist/google-workspace-connectors.test.js.map +1 -1
- package/dist/google-workspace-setup-links.test.d.ts +2 -0
- package/dist/google-workspace-setup-links.test.d.ts.map +1 -0
- package/dist/google-workspace-setup-links.test.js +26 -0
- package/dist/google-workspace-setup-links.test.js.map +1 -0
- package/dist/headless/channels.d.ts +142 -0
- package/dist/headless/channels.d.ts.map +1 -0
- package/dist/headless/channels.js +103 -0
- package/dist/headless/channels.js.map +1 -0
- package/dist/headless/events.d.ts +48 -0
- package/dist/headless/events.d.ts.map +1 -0
- package/dist/headless/events.js +29 -0
- package/dist/headless/events.js.map +1 -0
- package/dist/headless/headless.test.d.ts +2 -0
- package/dist/headless/headless.test.d.ts.map +1 -0
- package/dist/headless/headless.test.js +240 -0
- package/dist/headless/headless.test.js.map +1 -0
- package/dist/headless/identity.d.ts +41 -0
- package/dist/headless/identity.d.ts.map +1 -0
- package/dist/headless/identity.js +17 -0
- package/dist/headless/identity.js.map +1 -0
- package/dist/headless/index.d.ts +8 -0
- package/dist/headless/index.d.ts.map +1 -0
- package/dist/headless/index.js +8 -0
- package/dist/headless/index.js.map +1 -0
- package/dist/headless/labels.d.ts +41 -0
- package/dist/headless/labels.d.ts.map +1 -0
- package/dist/headless/labels.js +133 -0
- package/dist/headless/labels.js.map +1 -0
- package/dist/headless/leases.d.ts +317 -0
- package/dist/headless/leases.d.ts.map +1 -0
- package/dist/headless/leases.js +194 -0
- package/dist/headless/leases.js.map +1 -0
- package/dist/headless/plans.d.ts +108 -0
- package/dist/headless/plans.d.ts.map +1 -0
- package/dist/headless/plans.js +230 -0
- package/dist/headless/plans.js.map +1 -0
- package/dist/headless/pure.d.ts +28 -0
- package/dist/headless/pure.d.ts.map +1 -0
- package/dist/headless/pure.js +111 -0
- package/dist/headless/pure.js.map +1 -0
- package/dist/headless/schemas.d.ts +59 -0
- package/dist/headless/schemas.d.ts.map +1 -0
- package/dist/headless/schemas.js +471 -0
- package/dist/headless/schemas.js.map +1 -0
- package/dist/index.d.ts +21 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +18 -6
- package/dist/index.js.map +1 -1
- package/dist/issue-creation-source.d.ts +9 -0
- package/dist/issue-creation-source.d.ts.map +1 -1
- package/dist/issue-creation-source.js +14 -0
- package/dist/issue-creation-source.js.map +1 -1
- package/dist/issue-references.d.ts.map +1 -1
- package/dist/issue-references.js +2 -0
- package/dist/issue-references.js.map +1 -1
- package/dist/issue-references.test.js +10 -0
- package/dist/issue-references.test.js.map +1 -1
- package/dist/leading-user-command.d.ts +49 -0
- package/dist/leading-user-command.d.ts.map +1 -0
- package/dist/leading-user-command.js +35 -0
- package/dist/leading-user-command.js.map +1 -0
- package/dist/leading-user-command.test.d.ts +2 -0
- package/dist/leading-user-command.test.d.ts.map +1 -0
- package/dist/leading-user-command.test.js +52 -0
- package/dist/leading-user-command.test.js.map +1 -0
- package/dist/onboarding-telemetry.d.ts +288 -0
- package/dist/onboarding-telemetry.d.ts.map +1 -0
- package/dist/onboarding-telemetry.js +356 -0
- package/dist/onboarding-telemetry.js.map +1 -0
- package/dist/question-set.d.ts +1 -0
- package/dist/question-set.d.ts.map +1 -1
- package/dist/question-set.js +22 -0
- package/dist/question-set.js.map +1 -1
- package/dist/run-diagnostics.d.ts +16 -0
- package/dist/run-diagnostics.d.ts.map +1 -0
- package/dist/run-diagnostics.js +59 -0
- package/dist/run-diagnostics.js.map +1 -0
- package/dist/run-failure-cause.d.ts +4 -0
- package/dist/run-failure-cause.d.ts.map +1 -1
- package/dist/run-failure-cause.js +7 -0
- package/dist/run-failure-cause.js.map +1 -1
- package/dist/run-failure-cause.test.js +8 -1
- package/dist/run-failure-cause.test.js.map +1 -1
- package/dist/sdk/client.d.ts +3 -0
- package/dist/sdk/client.d.ts.map +1 -0
- package/dist/sdk/client.js +869 -0
- package/dist/sdk/client.js.map +1 -0
- package/dist/sdk/env.d.ts +33 -0
- package/dist/sdk/env.d.ts.map +1 -0
- package/dist/sdk/env.js +254 -0
- package/dist/sdk/env.js.map +1 -0
- package/dist/sdk/index.d.ts +5 -0
- package/dist/sdk/index.d.ts.map +1 -0
- package/dist/sdk/index.js +5 -0
- package/dist/sdk/index.js.map +1 -0
- package/dist/sdk/lite.d.ts +6 -0
- package/dist/sdk/lite.d.ts.map +1 -0
- package/dist/sdk/lite.js +5 -0
- package/dist/sdk/lite.js.map +1 -0
- package/dist/sdk/memory-backend.d.ts +54 -0
- package/dist/sdk/memory-backend.d.ts.map +1 -0
- package/dist/sdk/memory-backend.js +2020 -0
- package/dist/sdk/memory-backend.js.map +1 -0
- package/dist/sdk/sdk.test.d.ts +2 -0
- package/dist/sdk/sdk.test.d.ts.map +1 -0
- package/dist/sdk/sdk.test.js +626 -0
- package/dist/sdk/sdk.test.js.map +1 -0
- package/dist/sdk/sse.d.ts +3 -0
- package/dist/sdk/sse.d.ts.map +1 -0
- package/dist/sdk/sse.js +80 -0
- package/dist/sdk/sse.js.map +1 -0
- package/dist/sdk/types.d.ts +210 -0
- package/dist/sdk/types.d.ts.map +1 -0
- package/dist/sdk/types.js +19 -0
- package/dist/sdk/types.js.map +1 -0
- package/dist/telemetry/connector-events.test.js +23 -1
- package/dist/telemetry/connector-events.test.js.map +1 -1
- package/dist/telemetry/events.d.ts +13 -0
- package/dist/telemetry/events.d.ts.map +1 -1
- package/dist/telemetry/events.js +14 -0
- package/dist/telemetry/events.js.map +1 -1
- package/dist/telemetry/generated/paperclip-telemetry.d.ts +57 -3
- package/dist/telemetry/generated/paperclip-telemetry.d.ts.map +1 -1
- package/dist/telemetry/generated/paperclip-telemetry.js +39 -0
- package/dist/telemetry/generated/paperclip-telemetry.js.map +1 -1
- package/dist/telemetry/index.d.ts +1 -1
- package/dist/telemetry/index.d.ts.map +1 -1
- package/dist/telemetry/index.js +1 -1
- package/dist/telemetry/index.js.map +1 -1
- package/dist/telemetry/retention.d.ts.map +1 -1
- package/dist/telemetry/retention.js +2 -0
- package/dist/telemetry/retention.js.map +1 -1
- package/dist/tool-catalog-availability.d.ts +10 -0
- package/dist/tool-catalog-availability.d.ts.map +1 -0
- package/dist/tool-catalog-availability.js +10 -0
- package/dist/tool-catalog-availability.js.map +1 -0
- package/dist/tool-catalog-availability.test.d.ts +2 -0
- package/dist/tool-catalog-availability.test.d.ts.map +1 -0
- package/dist/tool-catalog-availability.test.js +17 -0
- package/dist/tool-catalog-availability.test.js.map +1 -0
- package/dist/types/attention.d.ts +28 -1
- package/dist/types/attention.d.ts.map +1 -1
- package/dist/types/attention.js.map +1 -1
- package/dist/types/document-annotation.d.ts +13 -1
- package/dist/types/document-annotation.d.ts.map +1 -1
- package/dist/types/execution-projection.d.ts +1 -1
- package/dist/types/execution-projection.d.ts.map +1 -1
- package/dist/types/heartbeat.d.ts +19 -1
- package/dist/types/heartbeat.d.ts.map +1 -1
- package/dist/types/index.d.ts +5 -5
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js.map +1 -1
- package/dist/types/instance.d.ts +13 -1
- package/dist/types/instance.d.ts.map +1 -1
- package/dist/types/instance.js.map +1 -1
- package/dist/types/issue.d.ts +31 -2
- package/dist/types/issue.d.ts.map +1 -1
- package/dist/types/plugin.d.ts +5 -0
- package/dist/types/plugin.d.ts.map +1 -1
- package/dist/types/responsibility.d.ts +4 -2
- package/dist/types/responsibility.d.ts.map +1 -1
- package/dist/types/tool-access.d.ts +21 -2
- package/dist/types/tool-access.d.ts.map +1 -1
- package/dist/types/tool-access.js.map +1 -1
- package/dist/upstream-failure-codes.d.ts +30 -0
- package/dist/upstream-failure-codes.d.ts.map +1 -0
- package/dist/upstream-failure-codes.js +82 -0
- package/dist/upstream-failure-codes.js.map +1 -0
- package/dist/upstream-failure-codes.test.d.ts +2 -0
- package/dist/upstream-failure-codes.test.d.ts.map +1 -0
- package/dist/upstream-failure-codes.test.js +55 -0
- package/dist/upstream-failure-codes.test.js.map +1 -0
- package/dist/validators/access.d.ts +12 -0
- package/dist/validators/access.d.ts.map +1 -1
- package/dist/validators/access.js +6 -0
- package/dist/validators/access.js.map +1 -1
- package/dist/validators/access.test.js +17 -0
- package/dist/validators/access.test.js.map +1 -1
- package/dist/validators/agent.d.ts +4 -0
- package/dist/validators/agent.d.ts.map +1 -1
- package/dist/validators/agent.js +2 -1
- package/dist/validators/agent.js.map +1 -1
- package/dist/validators/agent.test.js +17 -1
- package/dist/validators/agent.test.js.map +1 -1
- package/dist/validators/app-definition.d.ts +4 -0
- package/dist/validators/app-definition.d.ts.map +1 -1
- package/dist/validators/chat-channels.test.js +11 -1
- package/dist/validators/chat-channels.test.js.map +1 -1
- package/dist/validators/company-portability.d.ts +5 -0
- package/dist/validators/company-portability.d.ts.map +1 -1
- package/dist/validators/document-annotation.d.ts +6 -0
- package/dist/validators/document-annotation.d.ts.map +1 -1
- package/dist/validators/document-annotation.js +2 -1
- package/dist/validators/document-annotation.js.map +1 -1
- package/dist/validators/index.d.ts +4 -4
- package/dist/validators/index.d.ts.map +1 -1
- package/dist/validators/index.js +4 -4
- package/dist/validators/index.js.map +1 -1
- package/dist/validators/instance.d.ts +6 -0
- package/dist/validators/instance.d.ts.map +1 -1
- package/dist/validators/instance.js +8 -2
- package/dist/validators/instance.js.map +1 -1
- package/dist/validators/instance.test.js +4 -2
- package/dist/validators/instance.test.js.map +1 -1
- package/dist/validators/issue.d.ts +211 -0
- package/dist/validators/issue.d.ts.map +1 -1
- package/dist/validators/issue.js +81 -4
- package/dist/validators/issue.js.map +1 -1
- package/dist/validators/issue.test.js +114 -1
- package/dist/validators/issue.test.js.map +1 -1
- package/dist/validators/plugin.d.ts +15 -0
- package/dist/validators/plugin.d.ts.map +1 -1
- package/dist/validators/plugin.js +28 -0
- package/dist/validators/plugin.js.map +1 -1
- package/dist/validators/plugin.test.js +31 -0
- package/dist/validators/plugin.test.js.map +1 -1
- package/dist/validators/secret.d.ts +4 -0
- package/dist/validators/secret.d.ts.map +1 -1
- package/dist/validators/secret.js +27 -0
- package/dist/validators/secret.js.map +1 -1
- package/dist/validators/tool-access.d.ts +6 -0
- package/dist/validators/tool-access.d.ts.map +1 -1
- package/dist/validators/tool-access.js +5 -7
- package/dist/validators/tool-access.js.map +1 -1
- package/dist/validators/tool-access.test.js +4 -1
- package/dist/validators/tool-access.test.js.map +1 -1
- package/package.json +9 -1
- package/dist/connection-intent-guidance.test.d.ts +0 -2
- package/dist/connection-intent-guidance.test.d.ts.map +0 -1
- package/dist/connection-intent-guidance.test.js +0 -24
- package/dist/connection-intent-guidance.test.js.map +0 -1
- package/dist/telemetry/readme-contract.test.d.ts +0 -2
- package/dist/telemetry/readme-contract.test.d.ts.map +0 -1
- package/dist/telemetry/readme-contract.test.js +0 -17
- package/dist/telemetry/readme-contract.test.js.map +0 -1
|
@@ -0,0 +1,626 @@
|
|
|
1
|
+
import { mkdtempSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { describe, expect, it } from "vitest";
|
|
5
|
+
import { createInMemoryPaperclipBackend, paperclip, PaperclipError, } from "./index.js";
|
|
6
|
+
describe("@paperclipai/sdk", () => {
|
|
7
|
+
it("resolves default company lazily and supports prefix or UUID", async () => {
|
|
8
|
+
const mem = createInMemoryPaperclipBackend({ companyPrefix: "PAP" });
|
|
9
|
+
const byDefault = paperclip({ fetch: mem.fetch });
|
|
10
|
+
const me = await byDefault.whoami();
|
|
11
|
+
expect(me.companyId).toBe(mem.companyId);
|
|
12
|
+
expect(me.companyPrefix).toBe("PAP");
|
|
13
|
+
const byPrefix = paperclip({ fetch: mem.fetch, company: "PAP" });
|
|
14
|
+
expect((await byPrefix.whoami()).companyId).toBe(mem.companyId);
|
|
15
|
+
const byUuid = paperclip({ fetch: mem.fetch, company: mem.companyId });
|
|
16
|
+
expect((await byUuid.whoami()).companyId).toBe(mem.companyId);
|
|
17
|
+
});
|
|
18
|
+
it("resolves Node ~/.paperclip context and profile keys automatically", async () => {
|
|
19
|
+
const homeDir = mkdtempSync(join(tmpdir(), "paperclip-sdk-home-"));
|
|
20
|
+
try {
|
|
21
|
+
mkdirSync(join(homeDir, ".paperclip", "profiles"), { recursive: true });
|
|
22
|
+
const mem = createInMemoryPaperclipBackend({
|
|
23
|
+
agentIdentityPolicy: "strict_agent_keys",
|
|
24
|
+
});
|
|
25
|
+
mem.seedAgent({ name: "scanner", role: "security", apiKey: "pcp_scanner_secret" });
|
|
26
|
+
mem.seedBoardToken({ token: "brd_human", userId: "user-dotta" });
|
|
27
|
+
writeFileSync(join(homeDir, ".paperclip", "context.json"), JSON.stringify({ companyId: mem.companyId, apiKey: "brd_human" }));
|
|
28
|
+
writeFileSync(join(homeDir, ".paperclip", "profiles", "scanner.json"), JSON.stringify({ agent_api_key: "pcp_scanner_secret" }));
|
|
29
|
+
const client = paperclip({ fetch: mem.fetch, homeDir });
|
|
30
|
+
// Human token with --as adhoc is rejected under strict_agent_keys
|
|
31
|
+
await expect(client.as("adhoc").whoami()).rejects.toMatchObject({
|
|
32
|
+
name: "PaperclipError",
|
|
33
|
+
status: 403,
|
|
34
|
+
code: "agent_key_required",
|
|
35
|
+
});
|
|
36
|
+
// Switching to .as("scanner") automatically loads ~/.paperclip/profiles/scanner.json
|
|
37
|
+
const scannerWho = await client.as("scanner").whoami();
|
|
38
|
+
expect(scannerWho.principalType).toBe("agent");
|
|
39
|
+
expect(scannerWho.agentName).toBe("scanner");
|
|
40
|
+
}
|
|
41
|
+
finally {
|
|
42
|
+
rmSync(homeDir, { recursive: true, force: true });
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
it("enforces delegated_profiles, registered agent collision, and scopes", async () => {
|
|
46
|
+
const mem = createInMemoryPaperclipBackend({
|
|
47
|
+
agentIdentityPolicy: "delegated_profiles",
|
|
48
|
+
});
|
|
49
|
+
mem.seedAgent({ name: "ceo", apiKey: "pcp_ceo_key" });
|
|
50
|
+
mem.seedBoardToken({ token: "brd_dotta", userId: "user-dotta" });
|
|
51
|
+
const anon = paperclip({ fetch: mem.fetch, company: mem.companyId });
|
|
52
|
+
await expect(anon.whoami()).rejects.toMatchObject({
|
|
53
|
+
status: 401,
|
|
54
|
+
code: "unauthorized",
|
|
55
|
+
});
|
|
56
|
+
const dotta = paperclip({
|
|
57
|
+
fetch: mem.fetch,
|
|
58
|
+
company: mem.companyId,
|
|
59
|
+
apiKey: "brd_dotta",
|
|
60
|
+
});
|
|
61
|
+
// Impersonating registered @ceo without key fails closed with 409
|
|
62
|
+
await expect(dotta.as("ceo").whoami()).rejects.toMatchObject({
|
|
63
|
+
status: 409,
|
|
64
|
+
code: "profile_matches_registered_agent",
|
|
65
|
+
});
|
|
66
|
+
// Ephemeral profile runs with X-Paperclip-Actor-Profile
|
|
67
|
+
const helper = dotta.as("worker-1");
|
|
68
|
+
const who = await helper.whoami();
|
|
69
|
+
expect(who.principalType).toBe("user");
|
|
70
|
+
expect(who.actorProfile).toBe("worker-1");
|
|
71
|
+
// Scoped handle restricts channels
|
|
72
|
+
const scoped = dotta.as("build-bot", {
|
|
73
|
+
scopes: { channels: ["build/*"], actions: ["read", "post"] },
|
|
74
|
+
});
|
|
75
|
+
const post = await scoped.post("build/auth", "CI passed");
|
|
76
|
+
expect(post.channel).toBe("build/auth");
|
|
77
|
+
await expect(scoped.post("deploys/prod", "No access")).rejects.toMatchObject({
|
|
78
|
+
status: 403,
|
|
79
|
+
code: "scope_denied",
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
it("supports lazy channels, passive posts, replies with --after guard, and subtree reads", async () => {
|
|
83
|
+
const mem = createInMemoryPaperclipBackend();
|
|
84
|
+
const board = paperclip({ fetch: mem.fetch }).as("lead");
|
|
85
|
+
const post1 = await board.post("build/auth", "Initial auth note", {
|
|
86
|
+
labels: { env: "dev" },
|
|
87
|
+
});
|
|
88
|
+
expect(post1.isPassivePost).toBe(true);
|
|
89
|
+
expect(post1.status).toBe("backlog");
|
|
90
|
+
expect(post1.description).toBeNull();
|
|
91
|
+
await board.post("build/ui", "UI lint clean");
|
|
92
|
+
await board.post("deploys/prod", "Prod green");
|
|
93
|
+
const buildSubtree = await board.read("build/");
|
|
94
|
+
expect(buildSubtree.kind).toBe("channel");
|
|
95
|
+
if (buildSubtree.kind === "channel") {
|
|
96
|
+
expect(buildSubtree.items.map((i) => i.channel)).toEqual([
|
|
97
|
+
"build/auth",
|
|
98
|
+
"build/ui",
|
|
99
|
+
]);
|
|
100
|
+
}
|
|
101
|
+
const r1 = await board.reply(post1.identifier, "First reply");
|
|
102
|
+
const r2 = await board.reply(post1.identifier, "Second reply", { after: r1.id });
|
|
103
|
+
expect(r2.body).toBe("Second reply");
|
|
104
|
+
// Stale --after returns 409 newer_message
|
|
105
|
+
await expect(board.reply(post1.identifier, "Stale reply", { after: r1.id })).rejects.toMatchObject({ status: 409, code: "newer_message" });
|
|
106
|
+
// Promote passive post to queued task preserving ID and history
|
|
107
|
+
const promoted = await board.tasks.create(post1.identifier, {
|
|
108
|
+
priority: "high",
|
|
109
|
+
labels: { role: "worker" },
|
|
110
|
+
});
|
|
111
|
+
expect(promoted.id).toBe(post1.id);
|
|
112
|
+
expect(promoted.status).toBe("todo");
|
|
113
|
+
const detail = await board.read(post1.identifier);
|
|
114
|
+
expect(detail.kind).toBe("thread");
|
|
115
|
+
if (detail.kind === "thread") {
|
|
116
|
+
expect(detail.comments).toHaveLength(2);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
it("handles CAS label updates and conflicts", async () => {
|
|
120
|
+
const mem = createInMemoryPaperclipBackend();
|
|
121
|
+
const board = paperclip({ fetch: mem.fetch });
|
|
122
|
+
const task = await board.tasks.create("triage", {
|
|
123
|
+
title: "Investigate spike",
|
|
124
|
+
labels: { stage: "new" },
|
|
125
|
+
});
|
|
126
|
+
const updated = await board.label(task.identifier, {
|
|
127
|
+
set: { stage: "investigating", owner: "agent-a" },
|
|
128
|
+
if: { stage: "new", owner: null },
|
|
129
|
+
});
|
|
130
|
+
expect(updated.kvLabels).toEqual({ stage: "investigating", owner: "agent-a" });
|
|
131
|
+
await expect(board.label(task.identifier, {
|
|
132
|
+
set: { stage: "investigating", owner: "agent-b" },
|
|
133
|
+
if: { stage: "new" },
|
|
134
|
+
})).rejects.toMatchObject({
|
|
135
|
+
status: 409,
|
|
136
|
+
code: "label_conflict",
|
|
137
|
+
});
|
|
138
|
+
await expect(board.label(task.identifier, { set: { "paperclip.pr": "123" } })).rejects.toMatchObject({ status: 400, code: "reserved_label" });
|
|
139
|
+
});
|
|
140
|
+
it("enforces schema immutability, block validation, and task resultSchema", async () => {
|
|
141
|
+
const mem = createInMemoryPaperclipBackend();
|
|
142
|
+
const board = paperclip({ fetch: mem.fetch });
|
|
143
|
+
const list = await board.schemas.list();
|
|
144
|
+
expect(list.some((s) => s.ref === "test-report@1")).toBe(true);
|
|
145
|
+
const def = {
|
|
146
|
+
type: "object",
|
|
147
|
+
required: ["passed"],
|
|
148
|
+
properties: { passed: { type: "boolean" } },
|
|
149
|
+
};
|
|
150
|
+
const first = await board.schemas.create({
|
|
151
|
+
ref: "audit-verdict@1",
|
|
152
|
+
jsonSchema: def,
|
|
153
|
+
});
|
|
154
|
+
expect(first.created).toBe(true);
|
|
155
|
+
const idempotent = await board.schemas.create({
|
|
156
|
+
ref: "audit-verdict@1",
|
|
157
|
+
jsonSchema: { properties: { passed: { type: "boolean" } }, required: ["passed"], type: "object" },
|
|
158
|
+
});
|
|
159
|
+
expect(idempotent.created).toBe(false);
|
|
160
|
+
await expect(board.schemas.create({
|
|
161
|
+
ref: "audit-verdict@1",
|
|
162
|
+
jsonSchema: { type: "object", required: ["passed", "extra"] },
|
|
163
|
+
})).rejects.toMatchObject({ status: 409, code: "schema_immutable" });
|
|
164
|
+
// Invalid block rejected on post
|
|
165
|
+
await expect(board.post("security/findings", "Bad finding", {
|
|
166
|
+
schema: { ref: "finding@1", data: { severity: "bogus" } },
|
|
167
|
+
})).rejects.toMatchObject({ status: 400, code: "invalid_schema_block" });
|
|
168
|
+
// Task with resultSchema requires valid data on complete()
|
|
169
|
+
const task = await board.tasks.create("security/audit", {
|
|
170
|
+
title: "Audit auth",
|
|
171
|
+
resultSchema: "audit-verdict@1",
|
|
172
|
+
});
|
|
173
|
+
const claim = await board.tasks.claim(task.identifier);
|
|
174
|
+
expect(claim).not.toBeNull();
|
|
175
|
+
await expect(claim.complete("Missing data")).rejects.toMatchObject({
|
|
176
|
+
status: 422,
|
|
177
|
+
code: "missing_or_invalid_result_schema",
|
|
178
|
+
});
|
|
179
|
+
const done = await claim.complete({
|
|
180
|
+
message: "Audit passed",
|
|
181
|
+
data: { passed: true },
|
|
182
|
+
});
|
|
183
|
+
expect(done.status).toBe("done");
|
|
184
|
+
expect(done.blocks[0]?.data).toEqual({ passed: true });
|
|
185
|
+
});
|
|
186
|
+
it("creates DAG plans, handles dependencies, lease expiry/claim_lost, and asks", async () => {
|
|
187
|
+
const mem = createInMemoryPaperclipBackend();
|
|
188
|
+
const web = mem.seedProject({ slug: "web-app", name: "Web App" });
|
|
189
|
+
const api = mem.seedProject({ slug: "api-server", name: "API Server" });
|
|
190
|
+
const lead = paperclip({ fetch: mem.fetch }).as("lead");
|
|
191
|
+
const plan = await lead.tasks.createPlan("build/auth", [
|
|
192
|
+
{
|
|
193
|
+
key: "review",
|
|
194
|
+
projectId: null,
|
|
195
|
+
title: "Review patch",
|
|
196
|
+
needs: ["patch"],
|
|
197
|
+
labels: { role: "reviewer" },
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
key: "patch",
|
|
201
|
+
title: "Patch token check",
|
|
202
|
+
labels: { role: "worker" },
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
key: "audit",
|
|
206
|
+
projectId: "api-server",
|
|
207
|
+
title: "Audit API",
|
|
208
|
+
labels: { role: "worker" },
|
|
209
|
+
},
|
|
210
|
+
], { projectId: "web-app", idempotencyKey: "auth-plan-1" });
|
|
211
|
+
expect(plan.tasks.map((t) => t.key)).toEqual(["patch", "review", "audit"]);
|
|
212
|
+
const patchItem = plan.tasks.find((t) => t.key === "patch");
|
|
213
|
+
const auditItem = plan.tasks.find((t) => t.key === "audit");
|
|
214
|
+
const reviewItem = plan.tasks.find((t) => t.key === "review");
|
|
215
|
+
expect(patchItem.issue.projectId).toBe(web.id);
|
|
216
|
+
expect(auditItem.issue.projectId).toBe(api.id);
|
|
217
|
+
expect(reviewItem.issue.projectId).toBeNull();
|
|
218
|
+
// Idempotent replay vs mismatch
|
|
219
|
+
const replay = await lead.tasks.createPlan("build/auth", [
|
|
220
|
+
{
|
|
221
|
+
key: "review",
|
|
222
|
+
projectId: null,
|
|
223
|
+
title: "Review patch",
|
|
224
|
+
needs: ["patch"],
|
|
225
|
+
labels: { role: "reviewer" },
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
key: "patch",
|
|
229
|
+
title: "Patch token check",
|
|
230
|
+
labels: { role: "worker" },
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
key: "audit",
|
|
234
|
+
projectId: "api-server",
|
|
235
|
+
title: "Audit API",
|
|
236
|
+
labels: { role: "worker" },
|
|
237
|
+
},
|
|
238
|
+
], { projectId: "web-app", idempotencyKey: "auth-plan-1" });
|
|
239
|
+
expect(replay.idempotentReplay).toBe(true);
|
|
240
|
+
await expect(lead.tasks.createPlan("build/auth", [{ key: "different", title: "Different payload" }], { idempotencyKey: "auth-plan-1" })).rejects.toMatchObject({
|
|
241
|
+
status: 409,
|
|
242
|
+
code: "duplicate_idempotency_key",
|
|
243
|
+
});
|
|
244
|
+
const w1 = paperclip({ fetch: mem.fetch }).as("worker-1");
|
|
245
|
+
// Reviewer cannot claim review yet because "patch" is not done
|
|
246
|
+
expect(await w1.tasks.claim({ channel: "build/auth", label: "role=reviewer" })).toBeNull();
|
|
247
|
+
// Worker 1 claims patch with 60s lease, then advances past expiry -> claim_lost
|
|
248
|
+
const c1 = await w1.tasks.claim({
|
|
249
|
+
channel: "build/auth",
|
|
250
|
+
label: "role=worker",
|
|
251
|
+
lease: "60s",
|
|
252
|
+
});
|
|
253
|
+
expect(c1).not.toBeNull();
|
|
254
|
+
expect(c1.task.identifier).toBe(patchItem.identifier);
|
|
255
|
+
// Renew works before expiry
|
|
256
|
+
const renewed = await c1.renew("2m");
|
|
257
|
+
expect(renewed.claimEpoch).toBe(c1.claimEpoch);
|
|
258
|
+
// Advance clock past 2m lease -> lease expires & requeues
|
|
259
|
+
mem.advanceTime(125_000);
|
|
260
|
+
await expect(c1.renew("1m")).rejects.toMatchObject({
|
|
261
|
+
status: 409,
|
|
262
|
+
code: "claim_lost",
|
|
263
|
+
});
|
|
264
|
+
// Worker 2 claims the requeued patch task & asks a human question (releases lease)
|
|
265
|
+
const w2 = paperclip({ fetch: mem.fetch }).as("worker-2");
|
|
266
|
+
const c2 = await w2.tasks.claim(patchItem.identifier);
|
|
267
|
+
expect(c2).not.toBeNull();
|
|
268
|
+
expect(c2.claimEpoch).toBeGreaterThan(c1.claimEpoch);
|
|
269
|
+
const interaction = await c2.confirm("Drop legacy column?", {
|
|
270
|
+
humanOnly: true,
|
|
271
|
+
});
|
|
272
|
+
expect(interaction.status).toBe("pending");
|
|
273
|
+
expect(interaction.continuationPolicy).toBe("requeue_on_resolve");
|
|
274
|
+
// Lead approves -> task returns to todo and worker claims + completes -> unblocks review!
|
|
275
|
+
await lead.approve(c2.task.identifier, { note: "Ship it" });
|
|
276
|
+
const c3 = await w2.tasks.claim(c2.task.identifier);
|
|
277
|
+
expect(c3).not.toBeNull();
|
|
278
|
+
await c3.complete("Patched");
|
|
279
|
+
// Review is now unblocked!
|
|
280
|
+
const revClaim = await w1.tasks.claim({
|
|
281
|
+
channel: "build/auth",
|
|
282
|
+
label: "role=reviewer",
|
|
283
|
+
});
|
|
284
|
+
expect(revClaim?.task.identifier).toBe(reviewItem.identifier);
|
|
285
|
+
});
|
|
286
|
+
it("supports wait() cursor replay, schedules, and SSE events() streaming", async () => {
|
|
287
|
+
const mem = createInMemoryPaperclipBackend();
|
|
288
|
+
const board = paperclip({ fetch: mem.fetch }).as("lead");
|
|
289
|
+
const task = await board.tasks.create("qa/smoke", { title: "Run smoke suite" });
|
|
290
|
+
const createdCursor = task.cursor;
|
|
291
|
+
// Complete task before calling wait() -> cursor replay returns immediately!
|
|
292
|
+
const claimed = await board.tasks.claim(task.identifier);
|
|
293
|
+
await claimed.complete("All green");
|
|
294
|
+
const replayed = await board.wait(task.identifier, {
|
|
295
|
+
event: ["task.completed", "task.failed"],
|
|
296
|
+
after: createdCursor,
|
|
297
|
+
timeout: "1s",
|
|
298
|
+
});
|
|
299
|
+
expect(replayed?.type).toBe("task.completed");
|
|
300
|
+
expect(replayed?.identifier).toBe(task.identifier);
|
|
301
|
+
// Schedules
|
|
302
|
+
const sched = await board.schedule("deploys", {
|
|
303
|
+
message: "Check canary",
|
|
304
|
+
in: "5m",
|
|
305
|
+
post: true,
|
|
306
|
+
});
|
|
307
|
+
expect(sched.status).toBe("scheduled");
|
|
308
|
+
expect((await board.schedules.list()).length).toBe(1);
|
|
309
|
+
expect((await board.schedules.cancel(sched.id)).cancelled).toBe(true);
|
|
310
|
+
// SSE stream replays from cursor and receives live events
|
|
311
|
+
const ac = new AbortController();
|
|
312
|
+
const received = [];
|
|
313
|
+
const streamTask = (async () => {
|
|
314
|
+
for await (const evt of board.events({ channel: "deploys/", after: createdCursor }, { signal: ac.signal })) {
|
|
315
|
+
received.push(evt.type);
|
|
316
|
+
if (received.length >= 2) {
|
|
317
|
+
ac.abort();
|
|
318
|
+
break;
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
})();
|
|
322
|
+
await board.post("deploys/prod", "Live SSE check 1");
|
|
323
|
+
await board.post("deploys/staging", "Live SSE check 2");
|
|
324
|
+
await streamTask;
|
|
325
|
+
expect(received).toEqual(["thread.posted", "thread.posted"]);
|
|
326
|
+
// Verify PaperclipError instance
|
|
327
|
+
try {
|
|
328
|
+
await board.read("PAP-99999");
|
|
329
|
+
expect.fail("Expected PaperclipError");
|
|
330
|
+
}
|
|
331
|
+
catch (err) {
|
|
332
|
+
expect(err).toBeInstanceOf(PaperclipError);
|
|
333
|
+
expect(err.status).toBe(404);
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
it("delegates tasks.create with needs to /issues/batch and prioritizes explicit profile key + v2 context", async () => {
|
|
337
|
+
const homeDir = mkdtempSync(join(tmpdir(), "paperclip-sdk-v2-"));
|
|
338
|
+
const prevApiKey = process.env.PAPERCLIP_API_KEY;
|
|
339
|
+
const prevCustomEnv = process.env.PAPERCLIP_TEST_V2_KEY;
|
|
340
|
+
try {
|
|
341
|
+
mkdirSync(join(homeDir, ".paperclip", "profiles"), { recursive: true });
|
|
342
|
+
const mem = createInMemoryPaperclipBackend({
|
|
343
|
+
agentIdentityPolicy: "delegated_profiles",
|
|
344
|
+
});
|
|
345
|
+
mem.seedAgent({ name: "worker-a", role: "engineer", apiKey: "pcp_worker_a" });
|
|
346
|
+
mem.seedBoardToken({ token: "brd_env_token", userId: "user-dotta" });
|
|
347
|
+
mem.seedBoardToken({ token: "brd_v2_token", userId: "user-v2" });
|
|
348
|
+
process.env.PAPERCLIP_TEST_V2_KEY = "brd_v2_token";
|
|
349
|
+
writeFileSync(join(homeDir, ".paperclip", "context.json"), JSON.stringify({
|
|
350
|
+
version: 2,
|
|
351
|
+
currentProfile: "default",
|
|
352
|
+
profiles: {
|
|
353
|
+
default: {
|
|
354
|
+
companyId: mem.companyId,
|
|
355
|
+
apiKeyEnvVarName: "PAPERCLIP_TEST_V2_KEY",
|
|
356
|
+
},
|
|
357
|
+
},
|
|
358
|
+
}));
|
|
359
|
+
writeFileSync(join(homeDir, ".paperclip", "profiles", "worker-a.json"), JSON.stringify({ agent_api_key: "pcp_worker_a" }));
|
|
360
|
+
// v2 context picks up apiKeyEnvVarName automatically when env PAPERCLIP_API_KEY is unset
|
|
361
|
+
delete process.env.PAPERCLIP_API_KEY;
|
|
362
|
+
const v2Client = paperclip({ fetch: mem.fetch, homeDir });
|
|
363
|
+
const v2Who = await v2Client.whoami();
|
|
364
|
+
expect(v2Who.companyId).toBe(mem.companyId);
|
|
365
|
+
expect(v2Who.userId).toBe("user-v2");
|
|
366
|
+
// Even with ambient PAPERCLIP_API_KEY set, explicit .as("worker-a") prefers profile key
|
|
367
|
+
process.env.PAPERCLIP_API_KEY = "brd_env_token";
|
|
368
|
+
const workerClient = paperclip({ fetch: mem.fetch, homeDir, company: mem.companyId }).as("worker-a");
|
|
369
|
+
const workerWho = await workerClient.whoami();
|
|
370
|
+
expect(workerWho.principalType).toBe("agent");
|
|
371
|
+
expect(workerWho.agentName).toBe("worker-a");
|
|
372
|
+
// tasks.create with needs delegates via batch endpoint and wires blockedByIssueIds
|
|
373
|
+
const first = await workerClient.tasks.create("eng", { title: "First step" });
|
|
374
|
+
const second = await workerClient.tasks.create("eng", {
|
|
375
|
+
title: "Second step",
|
|
376
|
+
needs: [first.identifier],
|
|
377
|
+
});
|
|
378
|
+
expect(second.blockedByIssueIds).toEqual([first.id]);
|
|
379
|
+
// wait(undefined, filters) forwards filter query params
|
|
380
|
+
const done = await workerClient.tasks.create("eng", { title: "Filter wait target" });
|
|
381
|
+
const doneClaim = await workerClient.tasks.claim(done.identifier);
|
|
382
|
+
await doneClaim.complete("Done");
|
|
383
|
+
const filteredWait = await workerClient.wait(undefined, {
|
|
384
|
+
event: "task.completed",
|
|
385
|
+
issueId: done.identifier,
|
|
386
|
+
after: done.cursor,
|
|
387
|
+
timeout: "500ms",
|
|
388
|
+
});
|
|
389
|
+
expect(filteredWait?.type).toBe("task.completed");
|
|
390
|
+
expect(filteredWait?.identifier).toBe(done.identifier);
|
|
391
|
+
}
|
|
392
|
+
finally {
|
|
393
|
+
if (prevApiKey === undefined)
|
|
394
|
+
delete process.env.PAPERCLIP_API_KEY;
|
|
395
|
+
else
|
|
396
|
+
process.env.PAPERCLIP_API_KEY = prevApiKey;
|
|
397
|
+
if (prevCustomEnv === undefined)
|
|
398
|
+
delete process.env.PAPERCLIP_TEST_V2_KEY;
|
|
399
|
+
else
|
|
400
|
+
process.env.PAPERCLIP_TEST_V2_KEY = prevCustomEnv;
|
|
401
|
+
rmSync(homeDir, { recursive: true, force: true });
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
it("ignores repo-local .paperclip/context.json credentials and refuses sending ambient keys to untrusted repo endpoints", async () => {
|
|
405
|
+
const repoDir = mkdtempSync(join(tmpdir(), "paperclip-sdk-untrusted-"));
|
|
406
|
+
const prevCwd = process.cwd();
|
|
407
|
+
const prevApiKey = process.env.PAPERCLIP_API_KEY;
|
|
408
|
+
const prevApiUrl = process.env.PAPERCLIP_API_URL;
|
|
409
|
+
const prevContext = process.env.PAPERCLIP_CONTEXT;
|
|
410
|
+
const prevHome = process.env.PAPERCLIP_HOME;
|
|
411
|
+
const prevCompany = process.env.PAPERCLIP_COMPANY_ID;
|
|
412
|
+
const prevProfile = process.env.PAPERCLIP_PROFILE;
|
|
413
|
+
const prevSecret = process.env.TEST_VICTIM_SECRET;
|
|
414
|
+
try {
|
|
415
|
+
delete process.env.PAPERCLIP_HOME;
|
|
416
|
+
delete process.env.PAPERCLIP_API_URL;
|
|
417
|
+
delete process.env.PAPERCLIP_COMPANY_ID;
|
|
418
|
+
delete process.env.PAPERCLIP_PROFILE;
|
|
419
|
+
process.env.TEST_VICTIM_SECRET = "victim-aws-secret";
|
|
420
|
+
process.env.PAPERCLIP_API_KEY = "brd_victim_ambient";
|
|
421
|
+
const trustedCtxPath = join(repoDir, "trusted-context.json");
|
|
422
|
+
writeFileSync(trustedCtxPath, JSON.stringify({
|
|
423
|
+
version: 2,
|
|
424
|
+
currentProfile: "default",
|
|
425
|
+
profiles: { default: { apiBase: "http://127.0.0.1:49991", companyId: "trusted-co" } },
|
|
426
|
+
}));
|
|
427
|
+
process.env.PAPERCLIP_CONTEXT = trustedCtxPath;
|
|
428
|
+
mkdirSync(join(repoDir, ".paperclip"), { recursive: true });
|
|
429
|
+
writeFileSync(join(repoDir, ".paperclip", "context.json"), JSON.stringify({
|
|
430
|
+
version: 2,
|
|
431
|
+
currentProfile: "default",
|
|
432
|
+
profiles: {
|
|
433
|
+
default: {
|
|
434
|
+
apiBase: "http://127.0.0.1:49999",
|
|
435
|
+
companyId: "attacker-co",
|
|
436
|
+
apiKey: "attacker-inline",
|
|
437
|
+
apiKeyEnvVarName: "TEST_VICTIM_SECRET",
|
|
438
|
+
},
|
|
439
|
+
},
|
|
440
|
+
}));
|
|
441
|
+
process.chdir(repoDir);
|
|
442
|
+
const seenAuthHeaders = [];
|
|
443
|
+
const sdkClient = paperclip({
|
|
444
|
+
fetch: async (_input, init) => {
|
|
445
|
+
seenAuthHeaders.push(new Headers(init?.headers).get("authorization"));
|
|
446
|
+
return new Response(JSON.stringify({ id: "attacker-co", name: "X", issuePrefix: "X", agentIdentityPolicy: "open_local_profiles", apiBase: "http://127.0.0.1:49999", created: false }), {
|
|
447
|
+
status: 200,
|
|
448
|
+
headers: { "content-type": "application/json" },
|
|
449
|
+
});
|
|
450
|
+
},
|
|
451
|
+
});
|
|
452
|
+
// With PAPERCLIP_API_KEY present, SDK refuses sending ambient key to untrusted repo-local .paperclip/context.json apiBase
|
|
453
|
+
await expect(sdkClient.whoami()).rejects.toThrow(/untrusted repo-local apiBase/i);
|
|
454
|
+
expect(seenAuthHeaders).toEqual([]);
|
|
455
|
+
// Even without PAPERCLIP_API_KEY, repo-local apiKeyEnvVarName / inline apiKey is ignored
|
|
456
|
+
delete process.env.PAPERCLIP_API_KEY;
|
|
457
|
+
const anonClient = paperclip({
|
|
458
|
+
fetch: async (_input, init) => {
|
|
459
|
+
seenAuthHeaders.push(new Headers(init?.headers).get("authorization"));
|
|
460
|
+
return new Response(JSON.stringify({
|
|
461
|
+
companyId: "attacker-co",
|
|
462
|
+
companyName: "X",
|
|
463
|
+
companyPrefix: "X",
|
|
464
|
+
principalType: "local_trusted",
|
|
465
|
+
userId: null,
|
|
466
|
+
agentId: null,
|
|
467
|
+
agentName: null,
|
|
468
|
+
actorProfile: null,
|
|
469
|
+
agentIdentityPolicy: "open_local_profiles",
|
|
470
|
+
scopes: null,
|
|
471
|
+
}), { status: 200, headers: { "content-type": "application/json" } });
|
|
472
|
+
},
|
|
473
|
+
});
|
|
474
|
+
await anonClient.whoami();
|
|
475
|
+
expect(seenAuthHeaders).toEqual([null, null]);
|
|
476
|
+
}
|
|
477
|
+
finally {
|
|
478
|
+
process.chdir(prevCwd);
|
|
479
|
+
if (prevApiKey === undefined)
|
|
480
|
+
delete process.env.PAPERCLIP_API_KEY;
|
|
481
|
+
else
|
|
482
|
+
process.env.PAPERCLIP_API_KEY = prevApiKey;
|
|
483
|
+
if (prevApiUrl === undefined)
|
|
484
|
+
delete process.env.PAPERCLIP_API_URL;
|
|
485
|
+
else
|
|
486
|
+
process.env.PAPERCLIP_API_URL = prevApiUrl;
|
|
487
|
+
if (prevContext === undefined)
|
|
488
|
+
delete process.env.PAPERCLIP_CONTEXT;
|
|
489
|
+
else
|
|
490
|
+
process.env.PAPERCLIP_CONTEXT = prevContext;
|
|
491
|
+
if (prevHome === undefined)
|
|
492
|
+
delete process.env.PAPERCLIP_HOME;
|
|
493
|
+
else
|
|
494
|
+
process.env.PAPERCLIP_HOME = prevHome;
|
|
495
|
+
if (prevCompany === undefined)
|
|
496
|
+
delete process.env.PAPERCLIP_COMPANY_ID;
|
|
497
|
+
else
|
|
498
|
+
process.env.PAPERCLIP_COMPANY_ID = prevCompany;
|
|
499
|
+
if (prevProfile === undefined)
|
|
500
|
+
delete process.env.PAPERCLIP_PROFILE;
|
|
501
|
+
else
|
|
502
|
+
process.env.PAPERCLIP_PROFILE = prevProfile;
|
|
503
|
+
if (prevSecret === undefined)
|
|
504
|
+
delete process.env.TEST_VICTIM_SECRET;
|
|
505
|
+
else
|
|
506
|
+
process.env.TEST_VICTIM_SECRET = prevSecret;
|
|
507
|
+
rmSync(repoDir, { recursive: true, force: true });
|
|
508
|
+
}
|
|
509
|
+
});
|
|
510
|
+
it("carries server-resolved cursor across 204 wait hops when after is omitted", async () => {
|
|
511
|
+
const seenAfterParams = [];
|
|
512
|
+
let callCount = 0;
|
|
513
|
+
const client = paperclip({
|
|
514
|
+
apiBase: "http://127.0.0.1:49991",
|
|
515
|
+
company: "00000000-0000-4000-8000-000000000001",
|
|
516
|
+
fetch: async (input) => {
|
|
517
|
+
const url = new URL(typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url);
|
|
518
|
+
seenAfterParams.push(url.searchParams.get("after"));
|
|
519
|
+
callCount += 1;
|
|
520
|
+
if (callCount === 1) {
|
|
521
|
+
return new Response(null, {
|
|
522
|
+
status: 204,
|
|
523
|
+
headers: { "x-paperclip-cursor": "evt_17" },
|
|
524
|
+
});
|
|
525
|
+
}
|
|
526
|
+
return new Response(JSON.stringify({
|
|
527
|
+
id: "evt-row-18",
|
|
528
|
+
cursor: "evt_18",
|
|
529
|
+
seq: 18,
|
|
530
|
+
companyId: "00000000-0000-4000-8000-000000000001",
|
|
531
|
+
type: "thread.posted",
|
|
532
|
+
channel: "deploys",
|
|
533
|
+
channelId: "ch-1",
|
|
534
|
+
issueId: "iss-1",
|
|
535
|
+
identifier: "PAP-18",
|
|
536
|
+
actor: { type: "user", userId: "u-1", agentId: null, name: null, profile: null },
|
|
537
|
+
payload: {},
|
|
538
|
+
createdAt: "2026-01-01T00:00:00.000Z",
|
|
539
|
+
}), { status: 200, headers: { "content-type": "application/json" } });
|
|
540
|
+
},
|
|
541
|
+
});
|
|
542
|
+
const event = await client.wait("deploys", { timeout: "50ms" });
|
|
543
|
+
expect(event?.cursor).toBe("evt_18");
|
|
544
|
+
expect(seenAfterParams).toEqual([null, "evt_17"]);
|
|
545
|
+
});
|
|
546
|
+
it("loads fallback board credential from auth.json for matching apiBase unless apiBase came from repo-local config", async () => {
|
|
547
|
+
const homeDir = mkdtempSync(join(tmpdir(), "paperclip-sdk-authjson-"));
|
|
548
|
+
const repoDir = mkdtempSync(join(tmpdir(), "paperclip-sdk-authrepo-"));
|
|
549
|
+
const prevHome = process.env.PAPERCLIP_HOME;
|
|
550
|
+
const prevAuthStore = process.env.PAPERCLIP_AUTH_STORE;
|
|
551
|
+
const prevCtx = process.env.PAPERCLIP_CONTEXT;
|
|
552
|
+
const prevKey = process.env.PAPERCLIP_API_KEY;
|
|
553
|
+
const prevUrl = process.env.PAPERCLIP_API_URL;
|
|
554
|
+
const prevCwd = process.cwd();
|
|
555
|
+
try {
|
|
556
|
+
delete process.env.PAPERCLIP_HOME;
|
|
557
|
+
delete process.env.PAPERCLIP_AUTH_STORE;
|
|
558
|
+
delete process.env.PAPERCLIP_CONTEXT;
|
|
559
|
+
delete process.env.PAPERCLIP_API_KEY;
|
|
560
|
+
delete process.env.PAPERCLIP_API_URL;
|
|
561
|
+
mkdirSync(join(homeDir, ".paperclip"), { recursive: true });
|
|
562
|
+
const mem = createInMemoryPaperclipBackend({
|
|
563
|
+
agentIdentityPolicy: "delegated_profiles",
|
|
564
|
+
});
|
|
565
|
+
mem.seedBoardToken({ token: "brd_from_auth_json", userId: "user-auth-json" });
|
|
566
|
+
writeFileSync(join(homeDir, ".paperclip", "auth.json"), JSON.stringify({
|
|
567
|
+
version: 1,
|
|
568
|
+
credentials: {
|
|
569
|
+
"http://127.0.0.1:49992": {
|
|
570
|
+
apiBase: "http://127.0.0.1:49992",
|
|
571
|
+
token: "brd_from_auth_json",
|
|
572
|
+
createdAt: "2026-01-01T00:00:00.000Z",
|
|
573
|
+
updatedAt: "2026-01-01T00:00:00.000Z",
|
|
574
|
+
},
|
|
575
|
+
},
|
|
576
|
+
}));
|
|
577
|
+
// Direct apiBase uses ~/.paperclip/auth.json fallback
|
|
578
|
+
const authed = paperclip({
|
|
579
|
+
apiBase: "http://127.0.0.1:49992/",
|
|
580
|
+
company: mem.companyId,
|
|
581
|
+
homeDir,
|
|
582
|
+
fetch: mem.fetch,
|
|
583
|
+
});
|
|
584
|
+
const who = await authed.as("worker-auth").whoami();
|
|
585
|
+
expect(who.principalType).toBe("user");
|
|
586
|
+
expect(who.userId).toBe("user-auth-json");
|
|
587
|
+
expect(who.actorProfile).toBe("worker-auth");
|
|
588
|
+
// Repo-local apiBase refuses to send stored auth.json token silently
|
|
589
|
+
mkdirSync(join(repoDir, ".git"));
|
|
590
|
+
writeFileSync(join(repoDir, ".paperclip.json"), JSON.stringify({ apiBase: "http://127.0.0.1:49992", companyId: mem.companyId }));
|
|
591
|
+
process.chdir(repoDir);
|
|
592
|
+
process.env.PAPERCLIP_AUTH_STORE = join(homeDir, ".paperclip", "auth.json");
|
|
593
|
+
const untrustedRepoClient = paperclip({ fetch: mem.fetch });
|
|
594
|
+
await expect(untrustedRepoClient.whoami()).rejects.toMatchObject({
|
|
595
|
+
status: 401,
|
|
596
|
+
code: "unauthorized",
|
|
597
|
+
});
|
|
598
|
+
}
|
|
599
|
+
finally {
|
|
600
|
+
process.chdir(prevCwd);
|
|
601
|
+
if (prevHome === undefined)
|
|
602
|
+
delete process.env.PAPERCLIP_HOME;
|
|
603
|
+
else
|
|
604
|
+
process.env.PAPERCLIP_HOME = prevHome;
|
|
605
|
+
if (prevAuthStore === undefined)
|
|
606
|
+
delete process.env.PAPERCLIP_AUTH_STORE;
|
|
607
|
+
else
|
|
608
|
+
process.env.PAPERCLIP_AUTH_STORE = prevAuthStore;
|
|
609
|
+
if (prevCtx === undefined)
|
|
610
|
+
delete process.env.PAPERCLIP_CONTEXT;
|
|
611
|
+
else
|
|
612
|
+
process.env.PAPERCLIP_CONTEXT = prevCtx;
|
|
613
|
+
if (prevKey === undefined)
|
|
614
|
+
delete process.env.PAPERCLIP_API_KEY;
|
|
615
|
+
else
|
|
616
|
+
process.env.PAPERCLIP_API_KEY = prevKey;
|
|
617
|
+
if (prevUrl === undefined)
|
|
618
|
+
delete process.env.PAPERCLIP_API_URL;
|
|
619
|
+
else
|
|
620
|
+
process.env.PAPERCLIP_API_URL = prevUrl;
|
|
621
|
+
rmSync(homeDir, { recursive: true, force: true });
|
|
622
|
+
rmSync(repoDir, { recursive: true, force: true });
|
|
623
|
+
}
|
|
624
|
+
});
|
|
625
|
+
});
|
|
626
|
+
//# sourceMappingURL=sdk.test.js.map
|