Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

AcpRegistryAuthenticationState.test.ts

99 lines4.1 KB

1import * as NodeServices from "@effect/platform-node/NodeServices";
2import { assert, it } from "@effect/vitest";
3import { AcpRegistrySettings, ProviderInstanceId } from "@t3tools/contracts";
4import * as Effect from "effect/Effect";
5import * as FileSystem from "effect/FileSystem";
6import * as Schema from "effect/Schema";
7​
8import { makeAcpRegistryAuthenticationState } from "./AcpRegistryAuthenticationState.ts";
9​
10const settings = Schema.decodeSync(AcpRegistrySettings)({ agentId: "devin" });
11​
12it.layer(NodeServices.layer)("ACP sign-in confirmation", (it) => {
13 it.effect("restores explicit sign-in across driver recreation and server restart", () =>
14 Effect.gen(function* () {
15 const fs = yield* FileSystem.FileSystem;
16 const cacheDir = yield* fs.makeTempDirectoryScoped();
17 const input = {
18 cacheDir,
19 instanceId: ProviderInstanceId.make("acp_devin"),
20 settings,
21 environment: [],
22 processEnvironment: { HOME: "/home/test" },
23 };
24 const first = yield* makeAcpRegistryAuthenticationState(input);
25 assert.isFalse(yield* first.get);
26 yield* first.set(true);
27 const recreated = yield* makeAcpRegistryAuthenticationState({
28 ...input,
29 settings: { ...settings, customModels: ["new-model"] },
30 });
31 assert.isTrue(yield* recreated.get);
32 // Both logout and an explicit authentication failure revoke confirmation.
33 yield* recreated.set(false);
34 const restarted = yield* makeAcpRegistryAuthenticationState(input);
35 assert.isFalse(yield* restarted.get);
36 }),
37 );
38​
39 it.effect(
40 "does not carry confirmation to a different agent, method, executable, or credential environment",
41 () =>
42 Effect.gen(function* () {
43 const fs = yield* FileSystem.FileSystem;
44 const cacheDir = yield* fs.makeTempDirectoryScoped();
45 const input = {
46 cacheDir,
47 instanceId: ProviderInstanceId.make("acp_devin"),
48 settings,
49 environment: [{ name: "DEVIN_TOKEN", value: "test-only-token", sensitive: true }],
50 processEnvironment: { HOME: "/home/test" },
51 };
52 for (const change of [
53 { settings: { ...settings, agentId: "other-agent" } },
54 { settings: { ...settings, authMethodId: "enterprise" } },
55 { settings: { ...settings, commandPath: "/other/devin" } },
56 { environment: [{ name: "DEVIN_TOKEN", value: "different-token", sensitive: true }] },
57 { processEnvironment: { HOME: "/home/other" } },
58 ]) {
59 const signedIn = yield* makeAcpRegistryAuthenticationState(input);
60 yield* signedIn.set(true);
61 const changed = yield* makeAcpRegistryAuthenticationState({ ...input, ...change });
62 assert.isFalse(yield* changed.get);
63 const restoredConfig = yield* makeAcpRegistryAuthenticationState(input);
64 assert.isFalse(yield* restoredConfig.get);
65 }
66 for (const name of yield* fs.readDirectory(cacheDir)) {
67 const contents = yield* fs.readFileString(`${cacheDir}/${name}`);
68 assert.isFalse(contents.includes("test-only-token"));
69 assert.isFalse(contents.includes("different-token"));
70 }
71 }),
72 );
73​
74 it.effect("ignores damaged confirmation and keeps another instance independent", () =>
75 Effect.gen(function* () {
76 const fs = yield* FileSystem.FileSystem;
77 const cacheDir = yield* fs.makeTempDirectoryScoped();
78 const input = {
79 cacheDir,
80 instanceId: ProviderInstanceId.make("acp_devin"),
81 settings,
82 environment: [],
83 processEnvironment: {},
84 };
85 const first = yield* makeAcpRegistryAuthenticationState(input);
86 yield* first.set(true);
87 const other = yield* makeAcpRegistryAuthenticationState({
88 ...input,
89 instanceId: ProviderInstanceId.make("acp_other"),
90 });
91 assert.isFalse(yield* other.get);
92 for (const name of yield* fs.readDirectory(cacheDir)) {
93 yield* fs.writeFileString(`${cacheDir}/${name}`, "invalid");
94 }
95 const restored = yield* makeAcpRegistryAuthenticationState(input);
96 assert.isFalse(yield* restored.get);
97 }),
98 );
99});