@poncho-ai/harness 0.29.0 → 0.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build.log +5 -5
- package/CHANGELOG.md +24 -0
- package/dist/index.d.ts +45 -1
- package/dist/index.js +466 -57
- package/package.json +2 -2
- package/src/agent-parser.ts +1 -1
- package/src/config.ts +7 -0
- package/src/harness.ts +61 -6
- package/src/index.ts +1 -0
- package/src/model-factory.ts +87 -0
- package/src/openai-codex-auth.ts +362 -0
- package/src/state.ts +4 -0
- package/test/agent-parser.test.ts +12 -0
- package/test/model-factory.test.ts +12 -2
- package/test/openai-codex-auth.test.ts +82 -0
|
@@ -17,7 +17,7 @@ describe("model factory", () => {
|
|
|
17
17
|
|
|
18
18
|
const model = provider("claude-3-opus-20240229");
|
|
19
19
|
expect(model).toBeDefined();
|
|
20
|
-
expect((model as { provider: string }).provider).toMatch(/^anthropic
|
|
20
|
+
expect((model as { provider: string }).provider).toMatch(/^anthropic(?:\.|$)/);
|
|
21
21
|
});
|
|
22
22
|
|
|
23
23
|
it("defaults to Anthropic when no provider specified", () => {
|
|
@@ -26,7 +26,7 @@ describe("model factory", () => {
|
|
|
26
26
|
|
|
27
27
|
const model = provider("claude-3-opus-20240229");
|
|
28
28
|
expect(model).toBeDefined();
|
|
29
|
-
expect((model as { provider: string }).provider).toMatch(/^anthropic
|
|
29
|
+
expect((model as { provider: string }).provider).toMatch(/^anthropic(?:\.|$)/);
|
|
30
30
|
});
|
|
31
31
|
|
|
32
32
|
it("normalizes provider names to lowercase", () => {
|
|
@@ -36,4 +36,14 @@ describe("model factory", () => {
|
|
|
36
36
|
const model = provider("gpt-4");
|
|
37
37
|
expect((model as { provider: string }).provider).toBe("openai.responses");
|
|
38
38
|
});
|
|
39
|
+
|
|
40
|
+
it("creates a function for OpenAI Codex provider", () => {
|
|
41
|
+
process.env.OPENAI_CODEX_REFRESH_TOKEN = "test-refresh-token";
|
|
42
|
+
const provider = createModelProvider("openai-codex");
|
|
43
|
+
expect(provider).toBeInstanceOf(Function);
|
|
44
|
+
|
|
45
|
+
const model = provider("gpt-5.3-codex");
|
|
46
|
+
expect(model).toBeDefined();
|
|
47
|
+
expect((model as { provider: string }).provider).toBe("openai.responses");
|
|
48
|
+
});
|
|
39
49
|
});
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { mkdtemp } from "node:fs/promises";
|
|
2
|
+
import { join } from "node:path";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
5
|
+
import {
|
|
6
|
+
deleteOpenAICodexSession,
|
|
7
|
+
getOpenAICodexAccessToken,
|
|
8
|
+
readOpenAICodexSession,
|
|
9
|
+
writeOpenAICodexSession,
|
|
10
|
+
} from "../src/openai-codex-auth.js";
|
|
11
|
+
|
|
12
|
+
const encodeJwt = (payload: Record<string, unknown>): string => {
|
|
13
|
+
const header = Buffer.from(JSON.stringify({ alg: "none", typ: "JWT" })).toString(
|
|
14
|
+
"base64url",
|
|
15
|
+
);
|
|
16
|
+
const body = Buffer.from(JSON.stringify(payload)).toString("base64url");
|
|
17
|
+
return `${header}.${body}.sig`;
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
describe("openai codex auth", () => {
|
|
21
|
+
afterEach(() => {
|
|
22
|
+
delete process.env.OPENAI_CODEX_AUTH_FILE;
|
|
23
|
+
vi.unstubAllGlobals();
|
|
24
|
+
vi.restoreAllMocks();
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it("writes, reads, and deletes local session file", async () => {
|
|
28
|
+
const dir = await mkdtemp(join(tmpdir(), "poncho-codex-auth-"));
|
|
29
|
+
process.env.OPENAI_CODEX_AUTH_FILE = join(dir, "openai-codex.json");
|
|
30
|
+
await writeOpenAICodexSession({
|
|
31
|
+
refreshToken: "rt_123",
|
|
32
|
+
accessToken: "at_123",
|
|
33
|
+
accessTokenExpiresAt: Date.now() + 60_000,
|
|
34
|
+
accountId: "acct_abc",
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const stored = await readOpenAICodexSession();
|
|
38
|
+
expect(stored?.refreshToken).toBe("rt_123");
|
|
39
|
+
expect(stored?.accessToken).toBe("at_123");
|
|
40
|
+
expect(stored?.accountId).toBe("acct_abc");
|
|
41
|
+
|
|
42
|
+
await deleteOpenAICodexSession();
|
|
43
|
+
const afterDelete = await readOpenAICodexSession();
|
|
44
|
+
expect(afterDelete).toBeUndefined();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("refreshes token from stored session and persists rotated values", async () => {
|
|
48
|
+
const dir = await mkdtemp(join(tmpdir(), "poncho-codex-refresh-"));
|
|
49
|
+
process.env.OPENAI_CODEX_AUTH_FILE = join(dir, "openai-codex.json");
|
|
50
|
+
await writeOpenAICodexSession({
|
|
51
|
+
refreshToken: "rt_old",
|
|
52
|
+
accessToken: "at_expired",
|
|
53
|
+
accessTokenExpiresAt: Date.now() - 1000,
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
const idToken = encodeJwt({
|
|
57
|
+
"https://api.openai.com/auth": { chatgpt_account_id: "acct_rotated" },
|
|
58
|
+
});
|
|
59
|
+
const fetchMock = vi.fn(async () => {
|
|
60
|
+
return {
|
|
61
|
+
ok: true,
|
|
62
|
+
json: async () => ({
|
|
63
|
+
access_token: "at_new",
|
|
64
|
+
refresh_token: "rt_new",
|
|
65
|
+
expires_in: 3600,
|
|
66
|
+
id_token: idToken,
|
|
67
|
+
}),
|
|
68
|
+
} as Response;
|
|
69
|
+
});
|
|
70
|
+
vi.stubGlobal("fetch", fetchMock);
|
|
71
|
+
|
|
72
|
+
const access = await getOpenAICodexAccessToken();
|
|
73
|
+
expect(access.accessToken).toBe("at_new");
|
|
74
|
+
expect(access.accountId).toBe("acct_rotated");
|
|
75
|
+
expect(fetchMock).toHaveBeenCalledTimes(1);
|
|
76
|
+
|
|
77
|
+
const stored = await readOpenAICodexSession();
|
|
78
|
+
expect(stored?.refreshToken).toBe("rt_new");
|
|
79
|
+
expect(stored?.accessToken).toBe("at_new");
|
|
80
|
+
expect(stored?.accountId).toBe("acct_rotated");
|
|
81
|
+
});
|
|
82
|
+
});
|