diff --git a/.github/workflows/auto-typescript-tests.yml b/.github/workflows/auto-typescript-tests.yml new file mode 100644 index 000000000..ed29b9b42 --- /dev/null +++ b/.github/workflows/auto-typescript-tests.yml @@ -0,0 +1,46 @@ +name: Zero-code agent (@traceai/auto) tests + +# The registry test reads every typescript/packages/traceai_* manifest, and the +# integration tests load the built instrumentors, so the whole workspace is built. +on: + pull_request: + branches: [dev, main] + paths: + - 'typescript/packages/traceai_auto/**' + - 'typescript/packages/fi-core/**' + - 'typescript/packages/fi-semantic-conventions/**' + - 'typescript/packages/traceai_*/package.json' + - 'spec/auto-instrumentation/**' + - 'typescript/pnpm-lock.yaml' + - 'typescript/package.json' + - 'typescript/tsconfig*' + - '.github/workflows/auto-typescript-tests.yml' + push: + branches: [dev] + workflow_dispatch: + +permissions: + contents: read + +jobs: + auto: + name: '@traceai/auto suite' + runs-on: ubuntu-24.04 + timeout-minutes: 45 + defaults: + run: + working-directory: typescript + steps: + - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + with: + persist-credentials: false + - uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 + with: + node-version: '22' + - run: corepack enable + - name: Install the workspace + run: pnpm install --frozen-lockfile --ignore-scripts + - name: Build every package in dependency order + run: pnpm run build:ordered + - name: Run the @traceai/auto suite + run: pnpm --filter @traceai/auto test diff --git a/typescript/packages/fi-core/scripts/postbuild.cjs b/typescript/packages/fi-core/scripts/postbuild.cjs index 945a9dc61..146c4e624 100644 --- a/typescript/packages/fi-core/scripts/postbuild.cjs +++ b/typescript/packages/fi-core/scripts/postbuild.cjs @@ -1,4 +1,6 @@ const fs = require('node:fs'); +// tsc does not emit privacy.json (it is not in any tsconfig include), so these byte-exact copies are +// the only ones: a consumer's `tsc --build` reference to fi-core cannot reserialize them. for (const dir of ['dist/src', 'dist/esm', 'dist/esnext']) { fs.copyFileSync('src/privacy.json', `${dir}/privacy.json`); } diff --git a/typescript/packages/fi-core/tsconfig.esm.json b/typescript/packages/fi-core/tsconfig.esm.json index 215220afa..1a5d8d352 100644 --- a/typescript/packages/fi-core/tsconfig.esm.json +++ b/typescript/packages/fi-core/tsconfig.esm.json @@ -8,8 +8,7 @@ "resolveJsonModule": true }, "include": [ - "src/**/*.ts", - "src/**/*.json" + "src/**/*.ts" ], "references": [], "exclude": [ diff --git a/typescript/packages/fi-core/tsconfig.esnext.json b/typescript/packages/fi-core/tsconfig.esnext.json index d8370f7a7..34e3a4d04 100644 --- a/typescript/packages/fi-core/tsconfig.esnext.json +++ b/typescript/packages/fi-core/tsconfig.esnext.json @@ -8,8 +8,7 @@ "resolveJsonModule": true }, "include": [ - "src/**/*.ts", - "src/**/*.json" + "src/**/*.ts" ], "references": [], "exclude": [ diff --git a/typescript/packages/fi-core/tsconfig.json b/typescript/packages/fi-core/tsconfig.json index cbc7b5c99..2fa2eed00 100644 --- a/typescript/packages/fi-core/tsconfig.json +++ b/typescript/packages/fi-core/tsconfig.json @@ -8,7 +8,7 @@ "baseUrl": "./src", "resolveJsonModule": true }, - "include": ["src/**/*.ts", "src/**/*.json", "test/**/*.ts"], + "include": ["src/**/*.ts", "test/**/*.ts"], "exclude": ["src/**/*.test.ts", "src/**/__tests__/**", "test/**/*.ts"], "references": [] } \ No newline at end of file diff --git a/typescript/packages/traceai_auto/test/config.test.ts b/typescript/packages/traceai_auto/test/config.test.ts index 016def1c4..22ebea08d 100644 --- a/typescript/packages/traceai_auto/test/config.test.ts +++ b/typescript/packages/traceai_auto/test/config.test.ts @@ -93,7 +93,13 @@ test.each(["api_key", "secret_key"])("S7 ignored %s from every config/profile so }); test("registry covers every instrumentation package and records exported class and targets", () => { const packages = resolve(__dirname, "../.."); - const paths = readdirSync(packages).filter(p => p.startsWith("traceai_") && p !== "traceai_auto"); + // Coding-agent tracers (@traceai/agent-core and the hook plugins built on it) are set up + // with `npx @traceai/agents`, not loaded by the zero-code agent, so they are not listed here. + const codingAgent = (path: string) => { + const manifest = JSON.parse(readFileSync(join(packages, path, "package.json"), "utf8")); + return manifest.name === "@traceai/agent-core" || "@traceai/agent-core" in (manifest.dependencies ?? {}); + }; + const paths = readdirSync(packages).filter(p => p.startsWith("traceai_") && p !== "traceai_auto" && !codingAgent(p)); expect(integrations).toHaveLength(paths.length); for (const path of paths) { const manifest = JSON.parse(readFileSync(join(packages, path, "package.json"), "utf8")); diff --git a/typescript/packages/traceai_auto/test/safety.test.ts b/typescript/packages/traceai_auto/test/safety.test.ts index 4204e3890..c93595646 100644 --- a/typescript/packages/traceai_auto/test/safety.test.ts +++ b/typescript/packages/traceai_auto/test/safety.test.ts @@ -63,7 +63,7 @@ test("consumer cancellation is OK with partial output and incomplete marker", as expect(spans[0].attributes["error.type"]).toBeUndefined(); }); test.each([["gzip", gzipSync], ["deflate", deflateSync]] as const)("encoded %s responses decode before parsing but retain application bytes", async (encoding, compress) => { - const bytes = compress(partial); globalThis.fetch = jest.fn(async () => new Response(bytes, { headers: { "content-type": "text/event-stream", "content-encoding": encoding } })); const h = hook(); + const bytes = compress(partial); globalThis.fetch = jest.fn(async () => new Response(new Uint8Array(bytes), { headers: { "content-type": "text/event-stream", "content-encoding": encoding } })); const h = hook(); expect(Buffer.from(await (await fetch(url, init)).arrayBuffer())).toEqual(bytes); await Promise.all([...h.pending]); expect(spans[0].attributes["output.value"]).toBe("partial"); expect(spans[0].attributes["traceai.wire.undecoded_encoding"]).toBeUndefined(); }); @@ -93,7 +93,7 @@ test("native fetch response metadata prevents re-decoding plain-text transcripti }); test("decompressed output is bounded independently of compressed size", async () => { const bytes = gzipSync('data: {"choices":[{"delta":{"content":"' + "x".repeat(10000) + '"}}]}\n\n'); - globalThis.fetch = jest.fn(async () => new Response(bytes, { headers: { "content-type": "text/event-stream", "content-encoding": "gzip" } })); const h = hook(512); + globalThis.fetch = jest.fn(async () => new Response(new Uint8Array(bytes), { headers: { "content-type": "text/event-stream", "content-encoding": "gzip" } })); const h = hook(512); await (await fetch(url, init)).arrayBuffer(); await Promise.all([...h.pending]); expect(spans[0].attributes["traceai.wire.truncated"]).toBe(true); expect(spans[0].attributes["output.value"]).toBeUndefined(); }); @@ -164,7 +164,7 @@ test("cloning a mutable custom Response preserves metadata and independent heade }); test.each([["gzip", gzipSync], ["deflate", deflateSync], ["br", brotliCompressSync]] as const)("%s ElevenLabs JSON audio decodes before base64 counting", async (encoding, compress) => { const text = JSON.stringify({ audio_base64: Buffer.alloc(128).toString("base64") }), bytes = compress(text); - globalThis.fetch = jest.fn(async () => new Response(bytes, { headers: { "content-type": "application/json", "content-encoding": encoding } })); const h = hook(); + globalThis.fetch = jest.fn(async () => new Response(new Uint8Array(bytes), { headers: { "content-type": "application/json", "content-encoding": encoding } })); const h = hook(); const target = "https://api.elevenlabs.io/v1/text-to-speech/voice/with-timestamps"; expect(Buffer.from(await (await fetch(target, { ...init, body: '{"text":"hello","model_id":"tts"}' })).arrayBuffer())).toEqual(bytes); await Promise.all([...h.pending]); expect(spans).toHaveLength(1);