Files
OmniRoute/tests/unit/trae-publiccred.test.ts
Chirag Singhal 47bc3317c1 fix(oauth): embed Trae OAuth client_id via resolvePublicCred (Hard Rule #11) (#6870)
* fix(oauth): embed Trae OAuth client_id via resolvePublicCred (Hard Rule #11)

* fix(quality): register tests/unit/trae-publiccred.test.ts in stryker tap.testFiles

The mutation test-coverage gate (check:mutation-test-coverage --strict) flags
new covering unit tests that mutate open-sse/utils/publicCreds.ts but aren't
listed in stryker.conf.json's tap.testFiles, so their mutant kills wouldn't
count. Register the new test file alphabetically.

Co-authored-by: Chirag Singhal <chirag127@users.noreply.github.com>

---------

Co-authored-by: Chirag Singhal <chirag127@users.noreply.github.com>
Co-authored-by: Diego Rodrigues de Sa e Souza <diegosouza.pw@gmail.com>
Co-authored-by: Diego Rodrigues de Sa e Souza <8016841+diegosouzapw@users.noreply.github.com>
2026-07-12 01:59:15 -03:00

39 lines
1.4 KiB
TypeScript

import { test } from "node:test";
import assert from "node:assert";
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
import { resolvePublicCred } from "../../open-sse/utils/publicCreds.ts";
const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
test("trae_id embedded default decodes to the public Trae OAuth client_id", () => {
assert.equal(resolvePublicCred("trae_id"), "en1oxy7wnw8j9n");
});
test("TRAE_OAUTH_CLIENT_ID env override wins over the embedded default", () => {
const prev = process.env.TRAE_OAUTH_CLIENT_ID;
process.env.TRAE_OAUTH_CLIENT_ID = "test-trae-client-id";
try {
assert.equal(resolvePublicCred("trae_id", "TRAE_OAUTH_CLIENT_ID"), "test-trae-client-id");
} finally {
if (prev === undefined) delete process.env.TRAE_OAUTH_CLIENT_ID;
else process.env.TRAE_OAUTH_CLIENT_ID = prev;
}
});
test("trae.ts no longer embeds the raw client_id literal (Hard Rule #11)", () => {
const src = fs.readFileSync(
path.join(repoRoot, "open-sse/executors/trae.ts"),
"utf8"
) as string;
assert.ok(
!src.includes("en1oxy7wnw8j9n"),
"trae.ts must resolve the client_id via resolvePublicCred(), not a string literal"
);
assert.ok(
src.includes('resolvePublicCred("trae_id", "TRAE_OAUTH_CLIENT_ID")'),
"trae.ts must call resolvePublicCred for the Trae client_id"
);
});