Files
hyperframes/packages/cli/src/auth/_test-utils.ts
Miguel Ángel cf1b04bb71 feat(cli): accept host-managed HeyGen access tokens (#5177)
* fix(auth): accept host-managed HeyGen access tokens

* fix(auth): share environment header validation

* docs(auth): condense credential resolver guidance

* fix(auth): report the account a browser login just signed in

Identify the account from the tokens the login issued, not a fresh credential
lookup that an environment token or API key outranks.

* docs(auth): list the host access token in the CLI credential order

* fix(cli): name a rejected host access token on publish

Publish told a host-token user to log in again, which cannot help while the token outranks the login.

* docs(auth): show the media credential order main resolves

* fix(cli): warn at logout that a host access token still signs commands

One map of environment credential variables, owned by the resolver, now feeds the logout warning and both publish messages.

* docs(auth): scope the media credential order to the audio scripts

* refactor(cli): read every env credential name from the resolver's map
2026-10-08 10:33:57 +00:00

56 lines
1.5 KiB
TypeScript

/**
* Shared fixtures for auth-module tests. Centralises the env-snapshot
* + tmp-config-dir pattern so resolver.test.ts and oauth.test.ts don't
* each maintain a copy of the same beforeEach/afterEach plumbing.
*
* Only loaded by `*.test.ts` — runtime code doesn't depend on it.
*/
import { promises as fs } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
const ENV_KEYS = [
"HEYGEN_API_KEY",
"HEYGEN_ACCESS_TOKEN",
"HYPERFRAMES_API_KEY",
"HEYGEN_CONFIG_DIR",
"HEYGEN_API_URL",
"HYPERFRAMES_OAUTH_CLIENT_ID",
] as const;
type EnvKey = (typeof ENV_KEYS)[number];
export interface EnvFixture {
/** Tmp config dir; deleted on `restore()`. */
dir: string;
/** Restore env + delete tmp dir. Idempotent. */
restore: () => Promise<void>;
}
/**
* Take a snapshot of the auth-related env, clear them, make a tmp
* `HEYGEN_CONFIG_DIR`, and return a `restore()` that undoes all of
* the above.
*/
export async function setupTempAuthEnv(prefix = "hf-auth-test-"): Promise<EnvFixture> {
const dir = await fs.mkdtemp(join(tmpdir(), prefix));
const saved: Partial<Record<EnvKey, string | undefined>> = {};
for (const k of ENV_KEYS) {
saved[k] = process.env[k];
delete process.env[k];
}
process.env["HEYGEN_CONFIG_DIR"] = dir;
const restore = async (): Promise<void> => {
for (const k of ENV_KEYS) {
const v = saved[k];
if (v === undefined) delete process.env[k];
else process.env[k] = v;
}
await fs.rm(dir, { recursive: true, force: true });
};
return { dir, restore };
}