Skip to content

Commit bc30b29

Browse files
lilyshen0722Sprint Impl
andauthored
test(cli): guard public Codex attribution env filtering (#2064)
Plant a caller http.extraHeader entry in the existing performRun fixture so the full attribution env differs from sandboxEnv at the adapter seam. The existing sandbox count assertion now fails if agent.js passes .env instead of .sandboxEnv. Replace the negative arrayContaining checks with independent not.toContain assertions, so any single leaked token, provider-key, or caller Git-config name fails the adapter test. Codex adapter and run-loop suites pass 121/121. A local .env mutation failed at the expected sandbox count assertion. Written by sprint-impl, a Commonly agent. Pod thread: https://commonly.me/v2/pods/6a692a1be833c668acdb84cf#message-76080 Agent-Model: codex/gpt-6/default Co-authored-by: Sprint Impl <WyJzcHJpbnQtaW1wbCIsImRlZmF1bHQiXQ@agents.commonly.invalid>
1 parent df522c6 commit bc30b29

2 files changed

Lines changed: 22 additions & 11 deletions

File tree

‎cli/__tests__/adapters.codex.test.mjs‎

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -489,16 +489,12 @@ describe('codex adapter — spawn()', () => {
489489
'COMMONLY_AGENT_SEAT_NAME',
490490
'COMMONLY_AGENT_ORIGINAL_HOOKS_PATH',
491491
]));
492-
expect(allowedShellEnvironment).not.toEqual(expect.arrayContaining([
493-
'GIT_CONFIG_KEY_1',
494-
'GIT_CONFIG_VALUE_1',
495-
]));
496-
expect(allowedShellEnvironment).not.toEqual(expect.arrayContaining([
497-
'COMMONLY_AGENT_TOKEN',
498-
'COMMONLY_TOKEN_FILE',
499-
'OPENAI_API_KEY',
500-
'SOME_SECRET',
501-
]));
492+
expect(allowedShellEnvironment).not.toContain('GIT_CONFIG_KEY_1');
493+
expect(allowedShellEnvironment).not.toContain('GIT_CONFIG_VALUE_1');
494+
expect(allowedShellEnvironment).not.toContain('COMMONLY_AGENT_TOKEN');
495+
expect(allowedShellEnvironment).not.toContain('COMMONLY_TOKEN_FILE');
496+
expect(allowedShellEnvironment).not.toContain('OPENAI_API_KEY');
497+
expect(allowedShellEnvironment).not.toContain('SOME_SECRET');
502498
const shellEnvironmentSet = cFlags.find((flag) => (
503499
flag.startsWith('shell_environment_policy.set=')
504500
));

‎cli/__tests__/run-loop.test.mjs‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,28 @@ const drainMicrotasks = async () => {
9292
}
9393
};
9494

95+
let savedGitConfig;
96+
9597
describe('performRun', () => {
9698
beforeEach(() => {
99+
savedGitConfig = new Map(['GIT_CONFIG_COUNT', 'GIT_CONFIG_KEY_0', 'GIT_CONFIG_VALUE_0']
100+
.map((name) => [name, process.env[name]]));
97101
jest.clearAllMocks();
98102
fs.rmSync(path.join(sessionsTmpDir, '.commonly'), { recursive: true, force: true });
99103
});
100104

101-
test('event with content → adapter.spawn → message posted → event acked', async () => {
105+
afterEach(() => {
106+
for (const [name, value] of savedGitConfig) {
107+
if (value === undefined) delete process.env[name];
108+
else process.env[name] = value;
109+
}
110+
});
111+
112+
test('event with content → adapter.spawn receives sandboxed attribution → reply posted → acked', async () => {
113+
// Make the full attribution env differ from sandboxEnv at the adapter seam.
114+
process.env.GIT_CONFIG_COUNT = '1';
115+
process.env.GIT_CONFIG_KEY_0 = 'http.extraHeader';
116+
process.env.GIT_CONFIG_VALUE_0 = 'Authorization: Bearer planted-caller-value';
102117
const events = [makeEvent({ payload: { content: 'hello from tester', deliveryId: 'delivery-abc' } })];
103118
const mockGet = jest.fn().mockResolvedValue({ events });
104119
const mockPost = jest.fn().mockResolvedValue({});

0 commit comments

Comments
 (0)