cache-apt-pkgs-action/test/instrumentation.test.ts
Andrew Walsh 9c915961c7
build: install ts-apt from GitHub instead of a local path (#231)
* build: install ts-apt from GitHub instead of a local path

package.json pointed ts-apt at file:../ts-apt, which only exists on a
dev machine, so every test suite in CI failed with "Cannot find package
'ts-apt'". ts-apt isn't on npm, so pin it to a commit on GitHub. Its
prepare script builds dist on install.

The dev:tsapt:link script used --save, which is how the local path got
committed. Use --no-save so linking a local ts-apt doesn't change
package.json, and restore with npm ci on unlink.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* test: clear GITHUB_RUN_ID when testing the run ID fallback

GitHub Actions always sets GITHUB_RUN_ID, so the fallback test failed
once CI could run the tests at all.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 16:53:27 -08:00

79 lines
2.3 KiB
TypeScript

import { Artifacts, Instruments } from "../src/instrumentation.ts";
import { afterEach, describe, expect, it, vi } from "vitest";
describe("instrumentation", () => {
afterEach(() => {
vi.restoreAllMocks();
vi.unstubAllEnvs();
});
const ARTIFACT_FILENAMES = [
"capa_app.log",
"capa_exec.log",
"cache_key.json",
"manifest_main.json",
"manifest_all.json",
];
describe("Artifacts", () => {
it("constructor initializes properties correctly", () => {
const dir = "/path/to/artifacts";
const debug = true;
const runId = "test-run-id";
const artifacts = new Artifacts(dir, ARTIFACT_FILENAMES, debug, runId);
expect(artifacts).toEqual({
dir: dir,
artifactFilenames: ARTIFACT_FILENAMES,
debug: debug,
runId: runId,
});
});
it("constructor generates a random runId when not provided", () => {
const dir = "/path/to/artifacts";
const debug = false;
// GitHub Actions sets this, so clear it to test the fallback.
vi.stubEnv("GITHUB_RUN_ID", undefined);
const artifacts = new Artifacts(dir, ARTIFACT_FILENAMES, debug);
expect(artifacts.runId).toMatch(/^ghrunid-notfound-/);
});
});
// describe("Instruments", () => {
// it("constructor initializes properties correctly", () => {
// const cacheDir = "/path/to/cache";
// const debug = true;
// const artifacts = new Artifacts(
// "/path/to/cache",
// ARTIFACT_FILENAMES,
// debug,
// );
// const instruments = new Instruments(cacheDir, debug, artifacts);
// expect(instruments).toEqual({
// cacheDir: cacheDir,
// debug: debug,
// artifacts: artifacts,
// appLogger: expect.toBeTypeOf("object"),
// execLogger: expect.toBeTypeOf("object"),
// });
// });
// it("constructor initializes artifacts when not provided", () => {
// const cacheDir = "/path/to/cache";
// const debug = false;
// const instruments = new Instruments(cacheDir, debug);
// expect(instruments).toEqual({
// cacheDir: cacheDir,
// debug: debug,
// artifacts: expect.toBeTypeOf("object"),
// appLogger: expect.toBeTypeOf("object"),
// execLogger: expect.toBeTypeOf("object"),
// });
// });
// });
});