Files
hyperframes/packages/inspector/tests/hostStartup.test.ts
T
Michael Wang 3485b815e8 fix(inspector): the inspection page reaches only its own server and public hosts (#7903)
* wip: paused before review

* test: cover credential files on the preview routes and the deploy notice

* refactor: name the inspector's file lookup for what it serves

* fix(cli): a link to a private file outside the project keeps its own left-out reason

* fix: escape the upload notice and skip private files from old manifests

* fix(inspector): the inspection page reaches only its own server and public hosts

* fix(inspector): release the page server when the proxy fails to start

* fix(inspector): open each source session in its own browser context
2026-11-16 02:45:13 +00:00

34 lines
1.3 KiB
TypeScript

import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { Server } from "node:http";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { afterEach, expect, it, vi } from "vitest";
import { Inspector } from "../src/service";
const listeningServers = (): number =>
(process as unknown as { _getActiveHandles(): unknown[] })
._getActiveHandles()
.filter((handle) => handle instanceof Server && handle.listening).length;
const projects: string[] = [];
afterEach(() => {
vi.unstubAllEnvs();
for (const dir of projects.splice(0)) rmSync(dir, { recursive: true, force: true });
});
it("leaves no page server listening when the network proxy cannot start", async () => {
const project = mkdtempSync(join(tmpdir(), "hf-inspect-startup-"));
projects.push(project);
writeFileSync(join(project, "index.html"), "<html><body></body></html>");
vi.stubEnv("HYPERFRAMES_CAPTURE_PROXY", "https://proxy.invalid");
const before = listeningServers();
const inspector = new Inspector(project, { instrument: false });
for (let attempt = 0; attempt < 3; attempt++) {
await expect(inspector.withPage(async () => undefined)).rejects.toThrow(/http:\/\/ proxy/);
}
await inspector.dispose();
expect(listeningServers()).toBe(before);
});