Skip to content

Commit 74f345b

Browse files
test: cover credential writer failure paths
1 parent ff5ee23 commit 74f345b

1 file changed

Lines changed: 66 additions & 0 deletions

File tree

test/credentials-cross-process.test.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,72 @@ function runCredentialWriter(env: Record<string, string>): Promise<ChildResult>
5252
describe('credentials cross-process writes', () => {
5353
beforeAll(() => {
5454
execNpm(['run', 'build'], { cwd: REPO_ROOT, stdio: 'pipe' });
55+
}, 60_000);
56+
57+
it('reports missing required child-process environment variables', async () => {
58+
const result = await runCredentialWriter({
59+
CRED_API_KEY: '',
60+
CRED_PATH: '',
61+
CRED_PROFILE: '',
62+
CRED_START_PATH: '',
63+
});
64+
65+
expect(result).toMatchObject({
66+
code: 1,
67+
signal: null,
68+
stdout: '',
69+
});
70+
expect(result.stderr).toContain(
71+
'CRED_PROFILE, CRED_PATH, CRED_API_KEY, and CRED_START_PATH are required',
72+
);
73+
});
74+
75+
it('reports a timed out child-process start marker', async () => {
76+
const tmpRoot = mkdtempSync(join(tmpdir(), 'testsprite-creds-timeout-'));
77+
78+
try {
79+
const startPath = join(tmpRoot, 'missing-start');
80+
const result = await runCredentialWriter({
81+
CRED_API_KEY: 'sk-child-timeout',
82+
CRED_PATH: join(tmpRoot, 'credentials'),
83+
CRED_PROFILE: 'child-timeout',
84+
CRED_START_PATH: startPath,
85+
});
86+
87+
expect(result).toMatchObject({
88+
code: 2,
89+
signal: null,
90+
stdout: '',
91+
});
92+
expect(result.stderr).toContain(`Timed out waiting for start marker: ${startPath}`);
93+
} finally {
94+
rmSync(tmpRoot, { force: true, recursive: true });
95+
}
96+
}, 15_000);
97+
98+
it('reports writeProfile failures from the child process', async () => {
99+
const tmpRoot = mkdtempSync(join(tmpdir(), 'testsprite-creds-write-error-'));
100+
101+
try {
102+
const startPath = join(tmpRoot, 'start');
103+
writeFileSync(startPath, 'go');
104+
105+
const result = await runCredentialWriter({
106+
CRED_API_KEY: 'sk-child-invalid-profile',
107+
CRED_PATH: join(tmpRoot, 'credentials'),
108+
CRED_PROFILE: 'bad]',
109+
CRED_START_PATH: startPath,
110+
});
111+
112+
expect(result).toMatchObject({
113+
code: 3,
114+
signal: null,
115+
stdout: '',
116+
});
117+
expect(result.stderr).toContain('Invalid request.');
118+
} finally {
119+
rmSync(tmpRoot, { force: true, recursive: true });
120+
}
55121
});
56122

57123
it('preserves every profile written by concurrent child processes', async () => {

0 commit comments

Comments
 (0)