Skip to content

Commit 7286fca

Browse files
Mossakaclaude
andcommitted
test: fix docker-warning tests and fragile timing dependencies
- Remove docker-warning.test.ts: skipped tests were redundant with no-docker.test.ts which already covers Docker removal behavior - Replace sleep 7 with retry loops in token-unset.test.ts: polls /proc/1/environ every 1s up to 15s instead of fixed sleep - Replace if(existsSync()) guards with hard expect() assertions in log-commands.test.ts so tests fail loudly instead of passing vacuously Closes #1046 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 6191d25 commit 7286fca

File tree

4 files changed

+96
-194
lines changed

4 files changed

+96
-194
lines changed

tests/integration/docker-warning.test.ts

Lines changed: 0 additions & 125 deletions
This file was deleted.

tests/integration/log-commands.test.ts

Lines changed: 41 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,16 @@ describe('Log Commands', () => {
4343
expect(result).toSucceed();
4444

4545
// Check that logs were created
46-
if (result.workDir) {
47-
const squidLogPath = path.join(result.workDir, 'squid-logs', 'access.log');
46+
expect(result.workDir).toBeTruthy();
47+
const squidLogPath = path.join(result.workDir!, 'squid-logs', 'access.log');
4848

49-
// Logs may not be immediately available due to buffering
50-
// Wait a moment for logs to be flushed
51-
await new Promise(resolve => setTimeout(resolve, 1000));
49+
// Logs may not be immediately available due to buffering
50+
// Wait a moment for logs to be flushed
51+
await new Promise(resolve => setTimeout(resolve, 1000));
5252

53-
if (fs.existsSync(squidLogPath)) {
54-
const logContent = fs.readFileSync(squidLogPath, 'utf-8');
55-
expect(logContent.length).toBeGreaterThan(0);
56-
}
57-
}
53+
expect(fs.existsSync(squidLogPath)).toBe(true);
54+
const logContent = fs.readFileSync(squidLogPath, 'utf-8');
55+
expect(logContent.length).toBeGreaterThan(0);
5856

5957
// Cleanup after test
6058
await cleanup(false);
@@ -72,27 +70,24 @@ describe('Log Commands', () => {
7270
);
7371

7472
// First curl should succeed, second should fail
75-
if (result.workDir) {
76-
const squidLogPath = path.join(result.workDir, 'squid-logs', 'access.log');
77-
78-
await new Promise(resolve => setTimeout(resolve, 1000));
79-
80-
if (fs.existsSync(squidLogPath)) {
81-
const logContent = fs.readFileSync(squidLogPath, 'utf-8');
82-
const parser = createLogParser();
83-
const entries = parser.parseSquidLog(logContent);
84-
85-
// Should have at least one entry
86-
if (entries.length > 0) {
87-
// Verify entry structure
88-
const entry = entries[0];
89-
expect(entry).toHaveProperty('timestamp');
90-
expect(entry).toHaveProperty('host');
91-
expect(entry).toHaveProperty('statusCode');
92-
expect(entry).toHaveProperty('decision');
93-
}
94-
}
95-
}
73+
expect(result.workDir).toBeTruthy();
74+
const squidLogPath2 = path.join(result.workDir!, 'squid-logs', 'access.log');
75+
76+
await new Promise(resolve => setTimeout(resolve, 1000));
77+
78+
expect(fs.existsSync(squidLogPath2)).toBe(true);
79+
const logContent = fs.readFileSync(squidLogPath2, 'utf-8');
80+
const parser = createLogParser();
81+
const entries = parser.parseSquidLog(logContent);
82+
83+
// Should have at least one entry
84+
expect(entries.length).toBeGreaterThan(0);
85+
// Verify entry structure
86+
const entry = entries[0];
87+
expect(entry).toHaveProperty('timestamp');
88+
expect(entry).toHaveProperty('host');
89+
expect(entry).toHaveProperty('statusCode');
90+
expect(entry).toHaveProperty('decision');
9691

9792
await cleanup(false);
9893
}, 120000);
@@ -108,27 +103,25 @@ describe('Log Commands', () => {
108103
}
109104
);
110105

111-
if (result.workDir) {
112-
const squidLogPath = path.join(result.workDir, 'squid-logs', 'access.log');
106+
expect(result.workDir).toBeTruthy();
107+
const squidLogPath3 = path.join(result.workDir!, 'squid-logs', 'access.log');
113108

114-
await new Promise(resolve => setTimeout(resolve, 1000));
109+
await new Promise(resolve => setTimeout(resolve, 1000));
115110

116-
if (fs.existsSync(squidLogPath)) {
117-
const logContent = fs.readFileSync(squidLogPath, 'utf-8');
118-
const parser = createLogParser();
119-
const entries = parser.parseSquidLog(logContent);
111+
expect(fs.existsSync(squidLogPath3)).toBe(true);
112+
const logContent3 = fs.readFileSync(squidLogPath3, 'utf-8');
113+
const parser3 = createLogParser();
114+
const entries3 = parser3.parseSquidLog(logContent3);
120115

121-
// Filter by decision
122-
const allowed = parser.filterByDecision(entries, 'allowed');
123-
const blocked = parser.filterByDecision(entries, 'blocked');
116+
// Should have at least one entry
117+
expect(entries3.length).toBeGreaterThan(0);
124118

125-
// We should have at least one allowed (github.com) and one blocked (example.com)
126-
// Note: Log parsing depends on timing and buffering
127-
if (entries.length > 0) {
128-
expect(allowed.length + blocked.length).toBeGreaterThanOrEqual(1);
129-
}
130-
}
131-
}
119+
// Filter by decision
120+
const allowed = parser3.filterByDecision(entries3, 'allowed');
121+
const blocked = parser3.filterByDecision(entries3, 'blocked');
122+
123+
// We should have at least one allowed (github.com) and one blocked (example.com)
124+
expect(allowed.length + blocked.length).toBeGreaterThanOrEqual(1);
132125

133126
await cleanup(false);
134127
}, 180000);

tests/integration/no-docker.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
*
1616
* Known Issue: Building locally may fail due to NodeSource repository issues.
1717
* If tests fail with "docker found" errors, the images need to be rebuilt and published.
18+
*
19+
* NOTE: docker-warning.test.ts was removed as redundant — the Docker stub-script
20+
* approach was superseded by removing docker-cli entirely. This file covers the
21+
* Docker removal behavior (command not found, no socket, graceful failure).
1822
*/
1923

2024
/// <reference path="../jest-custom-matchers.d.ts" />

tests/integration/token-unset.test.ts

Lines changed: 51 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,21 @@ describe('Token Unsetting from Entrypoint Environ', () => {
2626
test('should unset GITHUB_TOKEN from /proc/1/environ after agent starts', async () => {
2727
const testToken = 'ghp_test_token_12345678901234567890';
2828

29-
// Command that checks /proc/1/environ after sleeping to allow token unsetting
29+
// Command that polls /proc/1/environ until token is cleared (retry loop)
3030
const command = `
31-
# Wait for entrypoint to unset tokens (5 second delay + 2 second buffer)
32-
sleep 7
33-
34-
# Check if GITHUB_TOKEN is still in /proc/1/environ
31+
# Poll /proc/1/environ until GITHUB_TOKEN is cleared (up to 15 seconds)
32+
for i in $(seq 1 15); do
33+
if ! cat /proc/1/environ | tr "\\0" "\\n" | grep -q "GITHUB_TOKEN="; then
34+
echo "SUCCESS: GITHUB_TOKEN cleared from /proc/1/environ"
35+
break
36+
fi
37+
sleep 1
38+
done
39+
40+
# Final check - fail if still present after retries
3541
if cat /proc/1/environ | tr "\\0" "\\n" | grep -q "GITHUB_TOKEN="; then
36-
echo "ERROR: GITHUB_TOKEN still in /proc/1/environ"
42+
echo "ERROR: GITHUB_TOKEN still in /proc/1/environ after 15 seconds"
3743
exit 1
38-
else
39-
echo "SUCCESS: GITHUB_TOKEN cleared from /proc/1/environ"
4044
fi
4145
4246
# Verify agent can still read the token (cached by one-shot-token library)
@@ -66,13 +70,18 @@ describe('Token Unsetting from Entrypoint Environ', () => {
6670
const testToken = 'sk-test_openai_key_1234567890';
6771

6872
const command = `
69-
sleep 7
73+
# Poll /proc/1/environ until OPENAI_API_KEY is cleared (up to 15 seconds)
74+
for i in $(seq 1 15); do
75+
if ! cat /proc/1/environ | tr "\\0" "\\n" | grep -q "OPENAI_API_KEY="; then
76+
echo "SUCCESS: OPENAI_API_KEY cleared from /proc/1/environ"
77+
break
78+
fi
79+
sleep 1
80+
done
7081
7182
if cat /proc/1/environ | tr "\\0" "\\n" | grep -q "OPENAI_API_KEY="; then
72-
echo "ERROR: OPENAI_API_KEY still in /proc/1/environ"
83+
echo "ERROR: OPENAI_API_KEY still in /proc/1/environ after 15 seconds"
7384
exit 1
74-
else
75-
echo "SUCCESS: OPENAI_API_KEY cleared from /proc/1/environ"
7685
fi
7786
7887
if [ -n "$OPENAI_API_KEY" ]; then
@@ -101,13 +110,18 @@ describe('Token Unsetting from Entrypoint Environ', () => {
101110
const testToken = 'sk-ant-test_key_1234567890';
102111

103112
const command = `
104-
sleep 7
113+
# Poll /proc/1/environ until ANTHROPIC_API_KEY is cleared (up to 15 seconds)
114+
for i in $(seq 1 15); do
115+
if ! cat /proc/1/environ | tr "\\0" "\\n" | grep -q "ANTHROPIC_API_KEY="; then
116+
echo "SUCCESS: ANTHROPIC_API_KEY cleared from /proc/1/environ"
117+
break
118+
fi
119+
sleep 1
120+
done
105121
106122
if cat /proc/1/environ | tr "\\0" "\\n" | grep -q "ANTHROPIC_API_KEY="; then
107-
echo "ERROR: ANTHROPIC_API_KEY still in /proc/1/environ"
123+
echo "ERROR: ANTHROPIC_API_KEY still in /proc/1/environ after 15 seconds"
108124
exit 1
109-
else
110-
echo "SUCCESS: ANTHROPIC_API_KEY cleared from /proc/1/environ"
111125
fi
112126
113127
if [ -n "$ANTHROPIC_API_KEY" ]; then
@@ -134,9 +148,19 @@ describe('Token Unsetting from Entrypoint Environ', () => {
134148

135149
test('should unset multiple tokens simultaneously', async () => {
136150
const command = `
137-
sleep 7
138-
139-
# Check all three tokens
151+
# Poll /proc/1/environ until all tokens are cleared (up to 15 seconds)
152+
for i in $(seq 1 15); do
153+
TOKENS_FOUND=0
154+
cat /proc/1/environ | tr "\\0" "\\n" | grep -q "GITHUB_TOKEN=" && TOKENS_FOUND=$((TOKENS_FOUND + 1))
155+
cat /proc/1/environ | tr "\\0" "\\n" | grep -q "OPENAI_API_KEY=" && TOKENS_FOUND=$((TOKENS_FOUND + 1))
156+
cat /proc/1/environ | tr "\\0" "\\n" | grep -q "ANTHROPIC_API_KEY=" && TOKENS_FOUND=$((TOKENS_FOUND + 1))
157+
if [ $TOKENS_FOUND -eq 0 ]; then
158+
break
159+
fi
160+
sleep 1
161+
done
162+
163+
# Final check - fail if any still present
140164
TOKENS_FOUND=0
141165
142166
if cat /proc/1/environ | tr "\\0" "\\n" | grep -q "GITHUB_TOKEN="; then
@@ -187,10 +211,16 @@ describe('Token Unsetting from Entrypoint Environ', () => {
187211

188212
test('should work in non-chroot mode', async () => {
189213
const command = `
190-
sleep 7
214+
# Poll /proc/1/environ until GITHUB_TOKEN is cleared (up to 15 seconds)
215+
for i in $(seq 1 15); do
216+
if ! cat /proc/1/environ | tr "\\0" "\\n" | grep -q "GITHUB_TOKEN="; then
217+
break
218+
fi
219+
sleep 1
220+
done
191221
192222
if cat /proc/1/environ | tr "\\0" "\\n" | grep -q "GITHUB_TOKEN="; then
193-
echo "ERROR: GITHUB_TOKEN still in /proc/1/environ"
223+
echo "ERROR: GITHUB_TOKEN still in /proc/1/environ after 15 seconds"
194224
exit 1
195225
else
196226
echo "SUCCESS: GITHUB_TOKEN cleared from /proc/1/environ in non-chroot mode"

0 commit comments

Comments
 (0)