Skip to content

Commit 775387f

Browse files
Mossakaclaude
andcommitted
fix: move Maven proxy config from docker-manager to workflow instruction
Instead of adding JAVA_TOOL_OPTIONS and Maven settings.xml generation to docker-manager.ts, instruct the agent to create ~/.m2/settings.xml with proxy settings before running Maven commands. This is simpler and doesn't require changes to the AWF core. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 2c4ac89 commit 775387f

4 files changed

Lines changed: 49 additions & 231 deletions

File tree

.github/workflows/build-test-java.lock.yml

Lines changed: 7 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.github/workflows/build-test-java.md

Lines changed: 38 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -45,55 +45,42 @@ env:
4545

4646
## Test Requirements
4747

48-
### 1. Verify Java Proxy Configuration
49-
50-
Before running any tests, verify that Java proxy configuration is properly set:
51-
52-
```bash
53-
# Verify JAVA_TOOL_OPTIONS is set
54-
echo "JAVA_TOOL_OPTIONS=$JAVA_TOOL_OPTIONS"
55-
56-
# Extract and display proxy settings
57-
java -XshowSettings:properties -version 2>&1 | grep -E "http\.(proxyHost|proxyPort|nonProxyHosts)|https\.(proxyHost|proxyPort)"
58-
```
59-
60-
**Expected configuration**:
61-
- `http.proxyHost` should be set to Squid IP (e.g., `172.30.0.10`)
62-
- `http.proxyPort` should be `3128`
63-
- `https.proxyHost` should be set to Squid IP
64-
- `https.proxyPort` should be `3128`
65-
- If host access is enabled, `http.nonProxyHosts` should include `localhost|127.0.0.1|host.docker.internal`
66-
67-
If proxy settings are missing or incorrect, report the issue and fail the workflow.
68-
69-
### 2. Clone Repository
70-
71-
`gh repo clone Mossaka/gh-aw-firewall-test-java /tmp/test-java`
72-
- **CRITICAL**: If clone fails, immediately call `safeoutputs-missing_tool` with message "CLONE_FAILED: Unable to clone test repository" and stop execution
73-
74-
### 3. Test Projects
75-
76-
Run Maven compile and test for each project:
77-
- `gson`: `cd /tmp/test-java/gson && mvn compile && mvn test`
78-
- `caffeine`: `cd /tmp/test-java/caffeine && mvn compile && mvn test`
79-
80-
### 4. Capture Results
81-
82-
For each project, capture:
83-
- Compile success/failure
84-
- Test pass/fail count
85-
- Any error messages
48+
Clone and test the following projects from the test repository:
49+
50+
1. **Clone Repository**: `gh repo clone Mossaka/gh-aw-firewall-test-java /tmp/test-java`
51+
- **CRITICAL**: If clone fails, immediately call `safeoutputs-missing_tool` with message "CLONE_FAILED: Unable to clone test repository" and stop execution
52+
53+
2. **Configure Maven Proxy**: Maven ignores Java system properties for proxy configuration, so you must create `~/.m2/settings.xml` before running any Maven commands:
54+
```bash
55+
mkdir -p ~/.m2
56+
cat > ~/.m2/settings.xml << SETTINGS
57+
<settings>
58+
<proxies>
59+
<proxy>
60+
<id>awf-http</id><active>true</active><protocol>http</protocol>
61+
<host>${SQUID_PROXY_HOST}</host><port>${SQUID_PROXY_PORT}</port>
62+
</proxy>
63+
<proxy>
64+
<id>awf-https</id><active>true</active><protocol>https</protocol>
65+
<host>${SQUID_PROXY_HOST}</host><port>${SQUID_PROXY_PORT}</port>
66+
</proxy>
67+
</proxies>
68+
</settings>
69+
SETTINGS
70+
```
71+
72+
3. **Test Projects**:
73+
- `gson`: `cd /tmp/test-java/gson && mvn compile && mvn test`
74+
- `caffeine`: `cd /tmp/test-java/caffeine && mvn compile && mvn test`
75+
76+
4. **For each project**, capture:
77+
- Compile success/failure
78+
- Test pass/fail count
79+
- Any error messages
8680
8781
## Output
8882
89-
Add a comment to the current pull request with a summary including:
90-
91-
1. **Java Proxy Configuration Status**:
92-
- ✅ Proxy settings verified OR ❌ Proxy settings missing/incorrect
93-
- Display the actual `JAVA_TOOL_OPTIONS` value
94-
- List detected proxy properties (http.proxyHost, http.proxyPort, https.proxyHost, https.proxyPort, http.nonProxyHosts if present)
95-
96-
2. **Build/Test Results Table**:
83+
Add a comment to the current pull request with a summary table:
9784
9885
| Project | Compile | Tests | Status |
9986
|----------|---------|-------|--------|
@@ -102,16 +89,15 @@ Add a comment to the current pull request with a summary including:
10289
10390
**Overall: PASS/FAIL**
10491
105-
If ALL tests pass AND proxy configuration is correct, add the label `build-test-java` to the pull request.
106-
If ANY test fails OR proxy configuration is incorrect, report the failure with error details.
92+
If ALL tests pass, add the label `build-test-java` to the pull request.
93+
If ANY test fails, report the failure with error details.
10794
10895
## Error Handling
10996
11097
**CRITICAL**: This workflow MUST fail visibly when errors occur:
11198
112-
1. **Proxy configuration failure**: If Java proxy settings are missing or incorrect, report in comment with actual vs expected values
113-
2. **Clone failure**: If repository clone fails, call `safeoutputs-missing_tool` with "CLONE_FAILED: [error message]"
114-
3. **Build failure**: Report in comment table with ❌ and include error output
115-
4. **Test failure**: Report in comment table with FAIL status and include failure details
99+
1. **Clone failure**: If repository clone fails, call `safeoutputs-missing_tool` with "CLONE_FAILED: [error message]"
100+
2. **Build failure**: Report in comment table with ❌ and include error output
101+
3. **Test failure**: Report in comment table with FAIL status and include failure details
116102
117103
DO NOT report success if any step fails. The workflow should produce a clear, actionable error message.

src/docker-manager.test.ts

Lines changed: 1 addition & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { generateDockerCompose, generateMavenSettings, subnetsOverlap, writeConfigs, startContainers, stopContainers, cleanup, runAgentCommand, validateIdNotInSystemRange, getSafeHostUid, getSafeHostGid, getRealUserHome, MIN_REGULAR_UID, ACT_PRESET_BASE_IMAGE } from './docker-manager';
1+
import { generateDockerCompose, subnetsOverlap, writeConfigs, startContainers, stopContainers, cleanup, runAgentCommand, validateIdNotInSystemRange, getSafeHostUid, getSafeHostGid, getRealUserHome, MIN_REGULAR_UID, ACT_PRESET_BASE_IMAGE } from './docker-manager';
22
import { WrapperConfig } from './types';
33
import * as fs from 'fs';
44
import * as path from 'path';
@@ -485,65 +485,6 @@ describe('docker-manager', () => {
485485
expect(env.SQUID_PROXY_PORT).toBe('3128');
486486
});
487487

488-
it('should configure JAVA_TOOL_OPTIONS with proxy settings for Java applications', () => {
489-
const result = generateDockerCompose(mockConfig, mockNetworkConfig);
490-
const agent = result.services.agent;
491-
const env = agent.environment as Record<string, string>;
492-
493-
expect(env.JAVA_TOOL_OPTIONS).toBeDefined();
494-
expect(env.JAVA_TOOL_OPTIONS).toContain('-Dhttp.proxyHost=172.30.0.10');
495-
expect(env.JAVA_TOOL_OPTIONS).toContain('-Dhttp.proxyPort=3128');
496-
expect(env.JAVA_TOOL_OPTIONS).toContain('-Dhttps.proxyHost=172.30.0.10');
497-
expect(env.JAVA_TOOL_OPTIONS).toContain('-Dhttps.proxyPort=3128');
498-
});
499-
500-
it('should add http.nonProxyHosts to JAVA_TOOL_OPTIONS when host access is enabled', () => {
501-
const configWithHostAccess = { ...mockConfig, enableHostAccess: true };
502-
const result = generateDockerCompose(configWithHostAccess, mockNetworkConfig);
503-
const agent = result.services.agent;
504-
const env = agent.environment as Record<string, string>;
505-
506-
expect(env.JAVA_TOOL_OPTIONS).toContain('-Dhttp.nonProxyHosts=');
507-
expect(env.JAVA_TOOL_OPTIONS).toContain('localhost');
508-
expect(env.JAVA_TOOL_OPTIONS).toContain('127.0.0.1');
509-
expect(env.JAVA_TOOL_OPTIONS).toContain('host.docker.internal');
510-
});
511-
512-
it('should not include quotes in JAVA_TOOL_OPTIONS nonProxyHosts value', () => {
513-
const configWithHostAccess = { ...mockConfig, enableHostAccess: true };
514-
const result = generateDockerCompose(configWithHostAccess, mockNetworkConfig);
515-
const agent = result.services.agent;
516-
const env = agent.environment as Record<string, string>;
517-
518-
// Verify no embedded quotes in nonProxyHosts value
519-
// JAVA_TOOL_OPTIONS parsing treats quotes as literal characters, not grouping
520-
expect(env.JAVA_TOOL_OPTIONS).not.toContain('"localhost');
521-
expect(env.JAVA_TOOL_OPTIONS).not.toContain('internal"');
522-
expect(env.JAVA_TOOL_OPTIONS).toContain('-Dhttp.nonProxyHosts=localhost|');
523-
});
524-
525-
it('should mount Maven settings.xml for proxy configuration', () => {
526-
const result = generateDockerCompose(mockConfig, mockNetworkConfig);
527-
const agent = result.services.agent;
528-
const volumes = agent.volumes as string[];
529-
530-
const mavenMount = volumes.find((v: string) => v.includes('maven-settings.xml'));
531-
expect(mavenMount).toBeDefined();
532-
expect(mavenMount).toContain('.m2/settings.xml:ro');
533-
});
534-
535-
it('should mount Maven settings.xml under /host in chroot mode', () => {
536-
const chrootConfig = { ...mockConfig, enableChroot: true };
537-
const result = generateDockerCompose(chrootConfig, mockNetworkConfig);
538-
const agent = result.services.agent;
539-
const volumes = agent.volumes as string[];
540-
541-
const mavenMount = volumes.find((v: string) => v.includes('maven-settings.xml'));
542-
expect(mavenMount).toBeDefined();
543-
expect(mavenMount).toContain('/host');
544-
expect(mavenMount).toContain('.m2/settings.xml:ro');
545-
});
546-
547488
it('should mount required volumes in agent container (default behavior)', () => {
548489
const result = generateDockerCompose(mockConfig, mockNetworkConfig);
549490
const agent = result.services.agent;
@@ -1871,32 +1812,4 @@ describe('docker-manager', () => {
18711812
await expect(cleanup(nonExistentDir, false)).resolves.not.toThrow();
18721813
});
18731814
});
1874-
1875-
describe('generateMavenSettings', () => {
1876-
it('should generate valid Maven settings.xml with proxy configuration', () => {
1877-
const result = generateMavenSettings('172.30.0.10', 3128);
1878-
1879-
expect(result).toContain('<settings');
1880-
expect(result).toContain('<proxies>');
1881-
expect(result).toContain('<protocol>http</protocol>');
1882-
expect(result).toContain('<protocol>https</protocol>');
1883-
expect(result).toContain('<host>172.30.0.10</host>');
1884-
expect(result).toContain('<port>3128</port>');
1885-
// Should not include nonProxyHosts when not provided
1886-
expect(result).not.toContain('<nonProxyHosts>');
1887-
});
1888-
1889-
it('should include nonProxyHosts when provided', () => {
1890-
const result = generateMavenSettings('172.30.0.10', 3128, 'localhost|127.0.0.1|host.docker.internal');
1891-
1892-
expect(result).toContain('<nonProxyHosts>localhost|127.0.0.1|host.docker.internal</nonProxyHosts>');
1893-
});
1894-
1895-
it('should have both HTTP and HTTPS proxy entries', () => {
1896-
const result = generateMavenSettings('172.30.0.10', 3128);
1897-
1898-
expect(result).toContain('<id>awf-http</id>');
1899-
expect(result).toContain('<id>awf-https</id>');
1900-
});
1901-
});
19021815
});

0 commit comments

Comments
 (0)