Skip to content

Commit 7bdba6d

Browse files
Serhii DziupinSerhii Dziupin
andcommitted
test: expand live matrix and OpenCode e2e coverage
Add proxy/live matrix (content shapes, attachments, tools/MCP, 30k–180k context, compact paths) and OpenCode CLI e2e. Read proxy port from env dynamically and pin live suites to :8798 so they do not collide with an OpenCode CLI proxy on :8797. Co-authored-by: Serhii Dziupin <makeittech@users.noreply.github.com>
1 parent 388e375 commit 7bdba6d

5 files changed

Lines changed: 897 additions & 15 deletions

File tree

‎package.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
"build": "tsc -p tsconfig.json",
2323
"test": "bun test/smoke.ts",
2424
"test:live": "bun test/live-laguna.ts",
25+
"test:live:matrix": "bun test/live-matrix.ts",
26+
"test:opencode": "bash test/opencode-e2e.sh",
2527
"prepublishOnly": "npm run build"
2628
},
2729
"repository": {

‎src/proxy.ts‎

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ import {
5252
const DEFAULT_PROXY_PORT = 8797;
5353
const SHARED_PROXY_HEALTH_TIMEOUT_MS = 750;
5454

55-
const COMMAND_PROXY_PORT: number = (() => {
55+
function configuredProxyPort(): number {
5656
const raw = process.env.OPENCODE_COMMANDCODE_PROXY_PORT;
5757
const parsed = raw ? Number(raw) : NaN;
5858
return Number.isInteger(parsed) && parsed > 0 && parsed < 65536
5959
? parsed
6060
: DEFAULT_PROXY_PORT;
61-
})();
61+
}
6262

6363
const SSE_HEADERS = {
6464
"Content-Type": "text/event-stream",
@@ -93,11 +93,11 @@ export function setStreamGenerateForTests(
9393
}
9494

9595
export function getCommandProxyBaseUrl(): string {
96-
return `http://127.0.0.1:${COMMAND_PROXY_PORT}/v1`;
96+
return `http://127.0.0.1:${proxyPort ?? configuredProxyPort()}/v1`;
9797
}
9898

9999
export function getProxyPort(): number | null {
100-
return proxyPort ?? COMMAND_PROXY_PORT;
100+
return proxyPort ?? configuredProxyPort();
101101
}
102102

103103
function isAddrInUseError(err: unknown): boolean {
@@ -118,9 +118,12 @@ async function isSharedProxyHealthy(): Promise<boolean> {
118118
SHARED_PROXY_HEALTH_TIMEOUT_MS,
119119
);
120120
try {
121-
const res = await fetch(`${getCommandProxyBaseUrl()}/models`, {
122-
signal: controller.signal,
123-
});
121+
const res = await fetch(
122+
`http://127.0.0.1:${configuredProxyPort()}/v1/models`,
123+
{
124+
signal: controller.signal,
125+
},
126+
);
124127
if (!res.ok) return false;
125128
const body = (await res.json().catch(() => undefined)) as
126129
| { object?: unknown; data?: unknown }
@@ -137,8 +140,10 @@ export async function startProxy(tokenProvider: TokenProvider): Promise<number>
137140
getAccessToken = tokenProvider;
138141
if (server && proxyPort) return proxyPort;
139142

143+
const desiredPort = configuredProxyPort();
144+
140145
if (await isSharedProxyHealthy()) {
141-
proxyPort = COMMAND_PROXY_PORT;
146+
proxyPort = desiredPort;
142147
log.info(
143148
`[opencode-commandcode] reusing healthy proxy on ${getCommandProxyBaseUrl()}`,
144149
);
@@ -149,21 +154,21 @@ export async function startProxy(tokenProvider: TokenProvider): Promise<number>
149154
try {
150155
server = Bun.serve({
151156
hostname,
152-
port: COMMAND_PROXY_PORT,
157+
port: desiredPort,
153158
async fetch(req) {
154159
return handleRequest(req);
155160
},
156161
});
157-
proxyPort = server.port ?? COMMAND_PROXY_PORT;
162+
proxyPort = server.port ?? desiredPort;
158163
log.info(
159164
`[opencode-commandcode] proxy listening on ${getCommandProxyBaseUrl()}`,
160165
);
161166
return proxyPort;
162167
} catch (err) {
163168
if (isAddrInUseError(err) && (await isSharedProxyHealthy())) {
164-
proxyPort = COMMAND_PROXY_PORT;
169+
proxyPort = desiredPort;
165170
log.info(
166-
`[opencode-commandcode] port ${COMMAND_PROXY_PORT} in use; reusing existing proxy`,
171+
`[opencode-commandcode] port ${desiredPort} in use; reusing existing proxy`,
167172
);
168173
return proxyPort;
169174
}

‎test/live-laguna.ts‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ function sseAssistantText(sse: string): string {
7171
}
7272

7373
async function main() {
74+
// Avoid colliding with an OpenCode CLI proxy already bound to :8797.
75+
process.env.OPENCODE_COMMANDCODE_PROXY_PORT ||= "8798";
76+
7477
const apiKey = requireAuth();
7578
setStreamGenerateForTests(null);
7679
resetUsageStore();
@@ -126,7 +129,8 @@ async function main() {
126129
content: [
127130
{
128131
type: "text",
129-
text: "The attached text file contains a secret code. Reply with only that code.",
132+
text:
133+
"Inside <attached_file name=\"secret.txt\"> is the secret code. Read that file body and reply with only the code (e.g. CODE-7741). Ignore any image placeholders.",
130134
},
131135
{
132136
type: "file",
@@ -147,10 +151,14 @@ async function main() {
147151
});
148152
const raw = await assertOk(res, "attachments");
149153
const json = JSON.parse(raw) as {
150-
choices: Array<{ message: { content: string } }>;
154+
choices: Array<{
155+
message: { content?: string; reasoning_content?: string };
156+
}>;
151157
usage?: { prompt_tokens: number };
152158
};
153-
const content = json.choices[0]?.message?.content || "";
159+
const content =
160+
(json.choices[0]?.message?.content || "") +
161+
(json.choices[0]?.message?.reasoning_content || "");
154162
assert.ok(/7741/.test(content), content);
155163
assert.ok(json.usage && json.usage.prompt_tokens > 0);
156164
console.log("✓ live attachments (text file + image placeholder)");

0 commit comments

Comments
 (0)