feat: v2
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import {
|
||||
runLogs,
|
||||
type LogApiEvent,
|
||||
type LogEventWriter,
|
||||
type LogsApiStream,
|
||||
} from "../../command/logs";
|
||||
|
||||
describe("logs API command runner", () => {
|
||||
test("uses the authenticated workspace NDJSON route and preserves prefixes", async () => {
|
||||
const calls: Array<{
|
||||
path: string;
|
||||
signal?: AbortSignal;
|
||||
timeout?: number;
|
||||
}> = [];
|
||||
const events: LogApiEvent[] = [
|
||||
{ type: "heartbeat", timestamp: "now" },
|
||||
{
|
||||
type: "log",
|
||||
targetName: "web",
|
||||
pod: "web-1",
|
||||
container: "web",
|
||||
message: "ready",
|
||||
},
|
||||
{
|
||||
type: "error",
|
||||
pod: "web-1",
|
||||
container: "web",
|
||||
message: "disconnected",
|
||||
retryable: true,
|
||||
},
|
||||
];
|
||||
const stream: LogsApiStream = async function* (path, init, options) {
|
||||
calls.push({
|
||||
path,
|
||||
signal: init?.signal ?? undefined,
|
||||
timeout: options?.timeoutMs,
|
||||
});
|
||||
yield* events as never[];
|
||||
};
|
||||
const output: Parameters<LogEventWriter>[] = [];
|
||||
const controller = new AbortController();
|
||||
await runLogs(
|
||||
"shop/demo",
|
||||
"web api",
|
||||
true,
|
||||
controller.signal,
|
||||
stream,
|
||||
(...entry) => output.push(entry),
|
||||
);
|
||||
|
||||
expect(calls).toEqual([
|
||||
{
|
||||
path: "/workspaces/shop%2Fdemo/logs?service=web+api&follow=true",
|
||||
signal: controller.signal,
|
||||
timeout: 0,
|
||||
},
|
||||
]);
|
||||
expect(output).toEqual([
|
||||
["web", "ready", false],
|
||||
["web api", "disconnected", true],
|
||||
]);
|
||||
});
|
||||
|
||||
test("omits follow for finite collection and passes cancellation", async () => {
|
||||
const controller = new AbortController();
|
||||
let receivedSignal: AbortSignal | null | undefined;
|
||||
const stream: LogsApiStream = async function* (path, init, options) {
|
||||
expect(path).toBe("/workspaces/shop/logs");
|
||||
expect(options?.timeoutMs).toBeUndefined();
|
||||
receivedSignal = init?.signal;
|
||||
yield* [];
|
||||
};
|
||||
await runLogs(
|
||||
"shop",
|
||||
undefined,
|
||||
false,
|
||||
controller.signal,
|
||||
stream,
|
||||
() => {},
|
||||
);
|
||||
expect(receivedSignal).toBe(controller.signal);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user