@united-workforce/cli 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -11
- package/dist/.build-fingerprint +1 -0
- package/dist/__tests__/adapter-json-roundtrip.test.js +17 -7
- package/dist/__tests__/adapter-json-roundtrip.test.js.map +1 -1
- package/dist/__tests__/agent-resolution-llm-free.test.d.ts +2 -0
- package/dist/__tests__/agent-resolution-llm-free.test.d.ts.map +1 -0
- package/dist/__tests__/agent-resolution-llm-free.test.js +30 -0
- package/dist/__tests__/agent-resolution-llm-free.test.js.map +1 -0
- package/dist/__tests__/build-step-entry.test.d.ts +2 -0
- package/dist/__tests__/build-step-entry.test.d.ts.map +1 -0
- package/dist/__tests__/build-step-entry.test.js +173 -0
- package/dist/__tests__/build-step-entry.test.js.map +1 -0
- package/dist/__tests__/clear-thread-failed-attempts.test.d.ts +2 -0
- package/dist/__tests__/clear-thread-failed-attempts.test.d.ts.map +1 -0
- package/dist/__tests__/clear-thread-failed-attempts.test.js +93 -0
- package/dist/__tests__/clear-thread-failed-attempts.test.js.map +1 -0
- package/dist/__tests__/concurrency.test.d.ts +2 -0
- package/dist/__tests__/concurrency.test.d.ts.map +1 -0
- package/dist/__tests__/concurrency.test.js +196 -0
- package/dist/__tests__/concurrency.test.js.map +1 -0
- package/dist/__tests__/config.test.js +26 -302
- package/dist/__tests__/config.test.js.map +1 -1
- package/dist/__tests__/current-role.test.js +7 -6
- package/dist/__tests__/current-role.test.js.map +1 -1
- package/dist/__tests__/e2e-mock-agent.test.js +43 -30
- package/dist/__tests__/e2e-mock-agent.test.js.map +1 -1
- package/dist/__tests__/format-text-default.test.d.ts +2 -0
- package/dist/__tests__/format-text-default.test.d.ts.map +1 -0
- package/dist/__tests__/format-text-default.test.js +43 -0
- package/dist/__tests__/format-text-default.test.js.map +1 -0
- package/dist/__tests__/format-text-registry.test.d.ts +2 -0
- package/dist/__tests__/format-text-registry.test.d.ts.map +1 -0
- package/dist/__tests__/format-text-registry.test.js +158 -0
- package/dist/__tests__/format-text-registry.test.js.map +1 -0
- package/dist/__tests__/issue-180-workflow-ref-removed.test.d.ts +2 -0
- package/dist/__tests__/issue-180-workflow-ref-removed.test.d.ts.map +1 -0
- package/dist/__tests__/issue-180-workflow-ref-removed.test.js +40 -0
- package/dist/__tests__/issue-180-workflow-ref-removed.test.js.map +1 -0
- package/dist/__tests__/log-text-renderer.test.d.ts +2 -0
- package/dist/__tests__/log-text-renderer.test.d.ts.map +1 -0
- package/dist/__tests__/log-text-renderer.test.js +265 -0
- package/dist/__tests__/log-text-renderer.test.js.map +1 -0
- package/dist/__tests__/moderator-evaluate.test.js +9 -50
- package/dist/__tests__/moderator-evaluate.test.js.map +1 -1
- package/dist/__tests__/output-mapper-thread-list-startedat.test.d.ts +2 -0
- package/dist/__tests__/output-mapper-thread-list-startedat.test.d.ts.map +1 -0
- package/dist/__tests__/output-mapper-thread-list-startedat.test.js +102 -0
- package/dist/__tests__/output-mapper-thread-list-startedat.test.js.map +1 -0
- package/dist/__tests__/output-mapper-workflow-add.test.d.ts +2 -0
- package/dist/__tests__/output-mapper-workflow-add.test.d.ts.map +1 -0
- package/dist/__tests__/output-mapper-workflow-add.test.js +22 -0
- package/dist/__tests__/output-mapper-workflow-add.test.js.map +1 -0
- package/dist/__tests__/pid-recycling.test.d.ts +2 -0
- package/dist/__tests__/pid-recycling.test.d.ts.map +1 -0
- package/dist/__tests__/pid-recycling.test.js +273 -0
- package/dist/__tests__/pid-recycling.test.js.map +1 -0
- package/dist/__tests__/prompt.test.js +365 -2
- package/dist/__tests__/prompt.test.js.map +1 -1
- package/dist/__tests__/resolve-head-hash.test.js +12 -4
- package/dist/__tests__/resolve-head-hash.test.js.map +1 -1
- package/dist/__tests__/setup-agent-discovery.test.js +21 -30
- package/dist/__tests__/setup-agent-discovery.test.js.map +1 -1
- package/dist/__tests__/setup-complexity.test.js +2 -168
- package/dist/__tests__/setup-complexity.test.js.map +1 -1
- package/dist/__tests__/setup-no-llm.test.d.ts +2 -0
- package/dist/__tests__/setup-no-llm.test.d.ts.map +1 -0
- package/dist/__tests__/setup-no-llm.test.js +52 -0
- package/dist/__tests__/setup-no-llm.test.js.map +1 -0
- package/dist/__tests__/solve-issue-tea-worktree.test.js +27 -28
- package/dist/__tests__/solve-issue-tea-worktree.test.js.map +1 -1
- package/dist/__tests__/step-ask.test.d.ts +2 -0
- package/dist/__tests__/step-ask.test.d.ts.map +1 -0
- package/dist/__tests__/step-ask.test.js +507 -0
- package/dist/__tests__/step-ask.test.js.map +1 -0
- package/dist/__tests__/step-show-json.test.js +1 -0
- package/dist/__tests__/step-show-json.test.js.map +1 -1
- package/dist/__tests__/step-timing.test.js +2 -0
- package/dist/__tests__/step-timing.test.js.map +1 -1
- package/dist/__tests__/store-global-cas.test.js +2 -2
- package/dist/__tests__/store-global-cas.test.js.map +1 -1
- package/dist/__tests__/store-unified-threads.test.js +28 -26
- package/dist/__tests__/store-unified-threads.test.js.map +1 -1
- package/dist/__tests__/thread-cancel-status.test.js +25 -19
- package/dist/__tests__/thread-cancel-status.test.js.map +1 -1
- package/dist/__tests__/thread-cancel-text-renderer.test.d.ts +2 -0
- package/dist/__tests__/thread-cancel-text-renderer.test.d.ts.map +1 -0
- package/dist/__tests__/thread-cancel-text-renderer.test.js +110 -0
- package/dist/__tests__/thread-cancel-text-renderer.test.js.map +1 -0
- package/dist/__tests__/thread-list-filters.test.js +354 -17
- package/dist/__tests__/thread-list-filters.test.js.map +1 -1
- package/dist/__tests__/thread-list-template-ms-date.test.d.ts +2 -0
- package/dist/__tests__/thread-list-template-ms-date.test.d.ts.map +1 -0
- package/dist/__tests__/thread-list-template-ms-date.test.js +102 -0
- package/dist/__tests__/thread-list-template-ms-date.test.js.map +1 -0
- package/dist/__tests__/thread-list-workflow-corrupt.test.d.ts +2 -0
- package/dist/__tests__/thread-list-workflow-corrupt.test.d.ts.map +1 -0
- package/dist/__tests__/thread-list-workflow-corrupt.test.js +157 -0
- package/dist/__tests__/thread-list-workflow-corrupt.test.js.map +1 -0
- package/dist/__tests__/thread-poke.test.d.ts +2 -0
- package/dist/__tests__/thread-poke.test.d.ts.map +1 -0
- package/dist/__tests__/thread-poke.test.js +422 -0
- package/dist/__tests__/thread-poke.test.js.map +1 -0
- package/dist/__tests__/thread-read-xml-tags.test.js +10 -9
- package/dist/__tests__/thread-read-xml-tags.test.js.map +1 -1
- package/dist/__tests__/thread-resume.test.js +21 -15
- package/dist/__tests__/thread-resume.test.js.map +1 -1
- package/dist/__tests__/thread-show-status.test.js +17 -28
- package/dist/__tests__/thread-show-status.test.js.map +1 -1
- package/dist/__tests__/thread-start-cwd-cli.test.js +15 -3
- package/dist/__tests__/thread-start-cwd-cli.test.js.map +1 -1
- package/dist/__tests__/thread-stop-text-renderer.test.d.ts +2 -0
- package/dist/__tests__/thread-stop-text-renderer.test.d.ts.map +1 -0
- package/dist/__tests__/thread-stop-text-renderer.test.js +148 -0
- package/dist/__tests__/thread-stop-text-renderer.test.js.map +1 -0
- package/dist/__tests__/thread-suspend-step.test.js +13 -16
- package/dist/__tests__/thread-suspend-step.test.js.map +1 -1
- package/dist/__tests__/thread-suspended-display.test.js +10 -22
- package/dist/__tests__/thread-suspended-display.test.js.map +1 -1
- package/dist/__tests__/thread-test-helpers.d.ts +7 -0
- package/dist/__tests__/thread-test-helpers.d.ts.map +1 -1
- package/dist/__tests__/thread-test-helpers.js +13 -0
- package/dist/__tests__/thread-test-helpers.js.map +1 -1
- package/dist/__tests__/thread.test.js +15 -13
- package/dist/__tests__/thread.test.js.map +1 -1
- package/dist/__tests__/validate-semantic.test.js +105 -23
- package/dist/__tests__/validate-semantic.test.js.map +1 -1
- package/dist/__tests__/workflow-list-recursive.test.d.ts +2 -0
- package/dist/__tests__/workflow-list-recursive.test.d.ts.map +1 -0
- package/dist/__tests__/workflow-list-recursive.test.js +286 -0
- package/dist/__tests__/workflow-list-recursive.test.js.map +1 -0
- package/dist/__tests__/workflow-resolution.test.js +46 -28
- package/dist/__tests__/workflow-resolution.test.js.map +1 -1
- package/dist/__tests__/workflow-show-resolution.test.d.ts +2 -0
- package/dist/__tests__/workflow-show-resolution.test.d.ts.map +1 -0
- package/dist/__tests__/workflow-show-resolution.test.js +213 -0
- package/dist/__tests__/workflow-show-resolution.test.js.map +1 -0
- package/dist/__tests__/workflow-validate.test.d.ts +2 -0
- package/dist/__tests__/workflow-validate.test.d.ts.map +1 -0
- package/dist/__tests__/workflow-validate.test.js +707 -0
- package/dist/__tests__/workflow-validate.test.js.map +1 -0
- package/dist/__tests__/write-envelope.test.d.ts +2 -0
- package/dist/__tests__/write-envelope.test.d.ts.map +1 -0
- package/dist/__tests__/write-envelope.test.js +201 -0
- package/dist/__tests__/write-envelope.test.js.map +1 -0
- package/dist/background/background.d.ts +22 -1
- package/dist/background/background.d.ts.map +1 -1
- package/dist/background/background.js +83 -6
- package/dist/background/background.js.map +1 -1
- package/dist/background/index.d.ts +1 -1
- package/dist/background/index.d.ts.map +1 -1
- package/dist/background/index.js +1 -1
- package/dist/background/index.js.map +1 -1
- package/dist/background/types.d.ts +1 -0
- package/dist/background/types.d.ts.map +1 -1
- package/dist/cli.js +120 -62
- package/dist/cli.js.map +1 -1
- package/dist/commands/config.d.ts +3 -1
- package/dist/commands/config.d.ts.map +1 -1
- package/dist/commands/config.js +17 -31
- package/dist/commands/config.js.map +1 -1
- package/dist/commands/prompt.d.ts.map +1 -1
- package/dist/commands/prompt.js +57 -31
- package/dist/commands/prompt.js.map +1 -1
- package/dist/commands/setup.d.ts +12 -39
- package/dist/commands/setup.d.ts.map +1 -1
- package/dist/commands/setup.js +72 -303
- package/dist/commands/setup.js.map +1 -1
- package/dist/commands/step.d.ts +44 -1
- package/dist/commands/step.d.ts.map +1 -1
- package/dist/commands/step.js +255 -11
- package/dist/commands/step.js.map +1 -1
- package/dist/commands/thread.d.ts +16 -3
- package/dist/commands/thread.d.ts.map +1 -1
- package/dist/commands/thread.js +423 -142
- package/dist/commands/thread.js.map +1 -1
- package/dist/commands/workflow.d.ts +9 -1
- package/dist/commands/workflow.d.ts.map +1 -1
- package/dist/commands/workflow.js +126 -6
- package/dist/commands/workflow.js.map +1 -1
- package/dist/concurrency/concurrency.d.ts +34 -0
- package/dist/concurrency/concurrency.d.ts.map +1 -0
- package/dist/concurrency/concurrency.js +216 -0
- package/dist/concurrency/concurrency.js.map +1 -0
- package/dist/concurrency/index.d.ts +3 -0
- package/dist/concurrency/index.d.ts.map +1 -0
- package/dist/concurrency/index.js +2 -0
- package/dist/concurrency/index.js.map +1 -0
- package/dist/concurrency/types.d.ts +19 -0
- package/dist/concurrency/types.d.ts.map +1 -0
- package/dist/concurrency/types.js +2 -0
- package/dist/concurrency/types.js.map +1 -0
- package/dist/format.d.ts +69 -2
- package/dist/format.d.ts.map +1 -1
- package/dist/format.js +198 -1
- package/dist/format.js.map +1 -1
- package/dist/moderator/__tests__/evaluate.test.js +31 -17
- package/dist/moderator/__tests__/evaluate.test.js.map +1 -1
- package/dist/moderator/evaluate.d.ts.map +1 -1
- package/dist/moderator/evaluate.js +4 -16
- package/dist/moderator/evaluate.js.map +1 -1
- package/dist/moderator/index.d.ts +1 -2
- package/dist/moderator/index.d.ts.map +1 -1
- package/dist/moderator/index.js +0 -1
- package/dist/moderator/index.js.map +1 -1
- package/dist/moderator/types.d.ts +6 -10
- package/dist/moderator/types.d.ts.map +1 -1
- package/dist/moderator/types.js +1 -3
- package/dist/moderator/types.js.map +1 -1
- package/dist/output-mappers.d.ts +122 -0
- package/dist/output-mappers.d.ts.map +1 -0
- package/dist/output-mappers.js +134 -0
- package/dist/output-mappers.js.map +1 -0
- package/dist/schemas.d.ts +6 -1
- package/dist/schemas.d.ts.map +1 -1
- package/dist/schemas.js +34 -5
- package/dist/schemas.js.map +1 -1
- package/dist/store.d.ts +28 -9
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +75 -16
- package/dist/store.js.map +1 -1
- package/dist/text-renderers.d.ts +30 -0
- package/dist/text-renderers.d.ts.map +1 -0
- package/dist/text-renderers.js +251 -0
- package/dist/text-renderers.js.map +1 -0
- package/dist/validate-semantic.d.ts.map +1 -1
- package/dist/validate-semantic.js +95 -61
- package/dist/validate-semantic.js.map +1 -1
- package/dist/validate.d.ts +6 -0
- package/dist/validate.d.ts.map +1 -1
- package/dist/validate.js +24 -0
- package/dist/validate.js.map +1 -1
- package/examples/brainstorm.yaml +130 -0
- package/examples/debate.yaml +169 -0
- package/examples/socratic-questioning.yaml +112 -0
- package/package.json +9 -10
- package/src/__tests__/adapter-json-roundtrip.test.ts +16 -7
- package/src/__tests__/agent-resolution-llm-free.test.ts +39 -0
- package/src/__tests__/build-step-entry.test.ts +203 -0
- package/src/__tests__/clear-thread-failed-attempts.test.ts +122 -0
- package/src/__tests__/concurrency.test.ts +266 -0
- package/src/__tests__/config.test.ts +33 -321
- package/src/__tests__/current-role.test.ts +7 -6
- package/src/__tests__/e2e-mock-agent.test.ts +65 -30
- package/src/__tests__/fixtures/e2e-count.workflow.yaml +1 -0
- package/src/__tests__/fixtures/e2e-linear.workflow.yaml +1 -0
- package/src/__tests__/fixtures/{e2e-mustache.workflow.yaml → e2e-liquid.workflow.yaml} +3 -2
- package/src/__tests__/fixtures/e2e-loop.workflow.yaml +1 -0
- package/src/__tests__/fixtures/e2e-suspend.mock.yaml +2 -2
- package/src/__tests__/fixtures/e2e-suspend.workflow.yaml +6 -10
- package/src/__tests__/format-text-default.test.ts +49 -0
- package/src/__tests__/format-text-registry.test.ts +173 -0
- package/src/__tests__/issue-180-workflow-ref-removed.test.ts +43 -0
- package/src/__tests__/log-text-renderer.test.ts +294 -0
- package/src/__tests__/moderator-evaluate.test.ts +9 -52
- package/src/__tests__/output-mapper-thread-list-startedat.test.ts +124 -0
- package/src/__tests__/output-mapper-workflow-add.test.ts +24 -0
- package/src/__tests__/pid-recycling.test.ts +329 -0
- package/src/__tests__/prompt.test.ts +443 -2
- package/src/__tests__/resolve-head-hash.test.ts +11 -4
- package/src/__tests__/setup-agent-discovery.test.ts +26 -51
- package/src/__tests__/setup-complexity.test.ts +1 -203
- package/src/__tests__/setup-no-llm.test.ts +68 -0
- package/src/__tests__/solve-issue-tea-worktree.test.ts +27 -31
- package/src/__tests__/step-ask.test.ts +677 -0
- package/src/__tests__/step-show-json.test.ts +1 -0
- package/src/__tests__/step-timing.test.ts +2 -0
- package/src/__tests__/store-global-cas.test.ts +2 -2
- package/src/__tests__/store-unified-threads.test.ts +30 -27
- package/src/__tests__/thread-cancel-status.test.ts +27 -20
- package/src/__tests__/thread-cancel-text-renderer.test.ts +125 -0
- package/src/__tests__/thread-list-filters.test.ts +443 -17
- package/src/__tests__/thread-list-template-ms-date.test.ts +110 -0
- package/src/__tests__/thread-list-workflow-corrupt.test.ts +198 -0
- package/src/__tests__/thread-poke.test.ts +554 -0
- package/src/__tests__/thread-read-xml-tags.test.ts +9 -11
- package/src/__tests__/thread-resume.test.ts +20 -15
- package/src/__tests__/thread-show-status.test.ts +17 -29
- package/src/__tests__/thread-start-cwd-cli.test.ts +15 -3
- package/src/__tests__/thread-stop-text-renderer.test.ts +168 -0
- package/src/__tests__/thread-suspend-step.test.ts +13 -16
- package/src/__tests__/thread-suspended-display.test.ts +10 -22
- package/src/__tests__/thread-test-helpers.ts +15 -1
- package/src/__tests__/thread.test.ts +14 -14
- package/src/__tests__/validate-semantic.test.ts +118 -33
- package/src/__tests__/workflow-list-recursive.test.ts +370 -0
- package/src/__tests__/workflow-resolution.test.ts +48 -29
- package/src/__tests__/workflow-show-resolution.test.ts +286 -0
- package/src/__tests__/workflow-validate.test.ts +828 -0
- package/src/__tests__/write-envelope.test.ts +257 -0
- package/src/background/background.ts +88 -6
- package/src/background/index.ts +2 -0
- package/src/background/types.ts +1 -0
- package/src/cli.ts +184 -77
- package/src/commands/config.ts +16 -33
- package/src/commands/prompt.ts +57 -31
- package/src/commands/setup.ts +80 -358
- package/src/commands/step.ts +339 -12
- package/src/commands/thread.ts +511 -171
- package/src/commands/workflow.ts +155 -4
- package/src/concurrency/concurrency.ts +245 -0
- package/src/concurrency/index.ts +10 -0
- package/src/concurrency/types.ts +19 -0
- package/src/format.ts +282 -2
- package/src/moderator/__tests__/evaluate.test.ts +34 -17
- package/src/moderator/evaluate.ts +5 -17
- package/src/moderator/index.ts +1 -6
- package/src/moderator/types.ts +6 -14
- package/src/output-mappers.ts +254 -0
- package/src/schemas.ts +51 -5
- package/src/store.ts +86 -20
- package/src/text-renderers.ts +355 -0
- package/src/validate-semantic.ts +125 -73
- package/src/validate.ts +27 -0
- package/dist/__tests__/setup-validate.test.d.ts +0 -2
- package/dist/__tests__/setup-validate.test.d.ts.map +0 -1
- package/dist/__tests__/setup-validate.test.js +0 -108
- package/dist/__tests__/setup-validate.test.js.map +0 -1
- package/src/__tests__/setup-validate.test.ts +0 -148
- /package/src/__tests__/fixtures/{e2e-mustache.mock.yaml → e2e-liquid.mock.yaml} +0 -0
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { mkdtemp, rm } from "node:fs/promises";
|
|
2
|
-
import { tmpdir } from "node:os";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
|
|
5
|
-
import { cmdSetup, validateModel } from "../commands/setup.js";
|
|
6
|
-
describe("validateModel", () => {
|
|
7
|
-
const BASE_URL = "https://api.example.com/v1";
|
|
8
|
-
const API_KEY = "sk-test-key";
|
|
9
|
-
const MODEL = "test-model";
|
|
10
|
-
afterEach(() => {
|
|
11
|
-
vi.restoreAllMocks();
|
|
12
|
-
});
|
|
13
|
-
test("success path — returns ok on 200", async () => {
|
|
14
|
-
const mockFetch = vi
|
|
15
|
-
.spyOn(globalThis, "fetch")
|
|
16
|
-
.mockResolvedValue(new Response(JSON.stringify({}), { status: 200 }));
|
|
17
|
-
const result = await validateModel(BASE_URL, API_KEY, MODEL);
|
|
18
|
-
expect(result).toEqual({ ok: true, value: undefined });
|
|
19
|
-
expect(mockFetch).toHaveBeenCalledTimes(1);
|
|
20
|
-
const [url, opts] = mockFetch.mock.calls[0];
|
|
21
|
-
expect(url).toBe(`${BASE_URL}/chat/completions`);
|
|
22
|
-
expect(opts.headers).toEqual(expect.objectContaining({ Authorization: `Bearer ${API_KEY}` }));
|
|
23
|
-
const body = JSON.parse(opts.body);
|
|
24
|
-
expect(body).toEqual({
|
|
25
|
-
model: MODEL,
|
|
26
|
-
messages: [{ role: "user", content: "hi" }],
|
|
27
|
-
max_tokens: 1,
|
|
28
|
-
});
|
|
29
|
-
});
|
|
30
|
-
test("HTTP 401 — returns error containing 401", async () => {
|
|
31
|
-
vi.spyOn(globalThis, "fetch").mockResolvedValue(new Response("Unauthorized", { status: 401, statusText: "Unauthorized" }));
|
|
32
|
-
const result = await validateModel(BASE_URL, API_KEY, MODEL);
|
|
33
|
-
expect(result.ok).toBe(false);
|
|
34
|
-
if (!result.ok) {
|
|
35
|
-
expect(result.error).toContain("401");
|
|
36
|
-
}
|
|
37
|
-
});
|
|
38
|
-
test("HTTP 404 — returns error containing 404", async () => {
|
|
39
|
-
vi.spyOn(globalThis, "fetch").mockResolvedValue(new Response("Not Found", { status: 404, statusText: "Not Found" }));
|
|
40
|
-
const result = await validateModel(BASE_URL, API_KEY, MODEL);
|
|
41
|
-
expect(result.ok).toBe(false);
|
|
42
|
-
if (!result.ok) {
|
|
43
|
-
expect(result.error).toContain("404");
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
test("network timeout — returns error mentioning timeout", async () => {
|
|
47
|
-
const err = new DOMException("signal timed out", "AbortError");
|
|
48
|
-
vi.spyOn(globalThis, "fetch").mockRejectedValue(err);
|
|
49
|
-
const result = await validateModel(BASE_URL, API_KEY, MODEL);
|
|
50
|
-
expect(result.ok).toBe(false);
|
|
51
|
-
if (!result.ok) {
|
|
52
|
-
expect(result.error.toLowerCase()).toMatch(/timeout|timed out/);
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
test("network error (DNS/connection) — returns error mentioning connectivity", async () => {
|
|
56
|
-
vi.spyOn(globalThis, "fetch").mockRejectedValue(new TypeError("fetch failed"));
|
|
57
|
-
const result = await validateModel(BASE_URL, API_KEY, MODEL);
|
|
58
|
-
expect(result.ok).toBe(false);
|
|
59
|
-
if (!result.ok) {
|
|
60
|
-
expect(result.error.toLowerCase()).toMatch(/connect|reach|network/);
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
test("request body correctness", async () => {
|
|
64
|
-
const mockFetch = vi
|
|
65
|
-
.spyOn(globalThis, "fetch")
|
|
66
|
-
.mockResolvedValue(new Response(JSON.stringify({}), { status: 200 }));
|
|
67
|
-
await validateModel(BASE_URL, API_KEY, "my-special-model");
|
|
68
|
-
const body = JSON.parse(mockFetch.mock.calls[0][1].body);
|
|
69
|
-
expect(body).toEqual({
|
|
70
|
-
model: "my-special-model",
|
|
71
|
-
messages: [{ role: "user", content: "hi" }],
|
|
72
|
-
max_tokens: 1,
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
describe("cmdSetup with validation", () => {
|
|
77
|
-
let storageRoot;
|
|
78
|
-
beforeEach(async () => {
|
|
79
|
-
storageRoot = await mkdtemp(join(tmpdir(), "uwf-setup-validate-"));
|
|
80
|
-
});
|
|
81
|
-
afterEach(async () => {
|
|
82
|
-
vi.restoreAllMocks();
|
|
83
|
-
await rm(storageRoot, { recursive: true, force: true });
|
|
84
|
-
});
|
|
85
|
-
const setupArgs = () => ({
|
|
86
|
-
provider: "testprovider",
|
|
87
|
-
baseUrl: "https://api.test.com/v1",
|
|
88
|
-
apiKey: "sk-test",
|
|
89
|
-
model: "test-model",
|
|
90
|
-
storageRoot,
|
|
91
|
-
});
|
|
92
|
-
test("includes validation result on success", async () => {
|
|
93
|
-
vi.spyOn(globalThis, "fetch").mockResolvedValue(new Response(JSON.stringify({}), { status: 200 }));
|
|
94
|
-
const result = await cmdSetup(setupArgs());
|
|
95
|
-
expect(result.validation).toEqual({ ok: true, value: undefined });
|
|
96
|
-
// Config file should still be written
|
|
97
|
-
expect(result.configPath).toBeTruthy();
|
|
98
|
-
});
|
|
99
|
-
test("includes validation failure — config still saved", async () => {
|
|
100
|
-
vi.spyOn(globalThis, "fetch").mockResolvedValue(new Response("Unauthorized", { status: 401, statusText: "Unauthorized" }));
|
|
101
|
-
const result = await cmdSetup(setupArgs());
|
|
102
|
-
expect(result.validation).toBeDefined();
|
|
103
|
-
expect(result.validation.ok).toBe(false);
|
|
104
|
-
// Config file should still be written despite validation failure
|
|
105
|
-
expect(result.configPath).toBeTruthy();
|
|
106
|
-
});
|
|
107
|
-
});
|
|
108
|
-
//# sourceMappingURL=setup-validate.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"setup-validate.test.js","sourceRoot":"","sources":["../../src/__tests__/setup-validate.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC3E,OAAO,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE/D,QAAQ,CAAC,eAAe,EAAE,GAAG,EAAE;IAC7B,MAAM,QAAQ,GAAG,4BAA4B,CAAC;IAC9C,MAAM,OAAO,GAAG,aAAa,CAAC;IAC9B,MAAM,KAAK,GAAG,YAAY,CAAC;IAE3B,SAAS,CAAC,GAAG,EAAE;QACb,EAAE,CAAC,eAAe,EAAE,CAAC;IACvB,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,kCAAkC,EAAE,KAAK,IAAI,EAAE;QAClD,MAAM,SAAS,GAAG,EAAE;aACjB,KAAK,CAAC,UAAU,EAAE,OAAO,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,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;QAClE,sCAAsC;QACtC,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,UAAU,EAAE,CAAC;IACzC,CAAC,CAAC,CAAC;IAEH,IAAI,CAAC,kDAAkD,EAAE,KAAK,IAAI,EAAE;QAClE,EAAE,CAAC,KAAK,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC,iBAAiB,CAC7C,IAAI,QAAQ,CAAC,cAAc,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,UAAU,EAAE,cAAc,EAAE,CAAC,CAC1E,CAAC;QAEF,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAC;QAE3C,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,WAAW,EAAE,CAAC;QACxC,MAAM,CAAE,MAAM,CAAC,UAA8B,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC9D,iEAAiE;QACjE,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,UAAU,EAAE,CAAC;IACzC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import { mkdtemp, rm } from "node:fs/promises";
|
|
2
|
-
import { tmpdir } from "node:os";
|
|
3
|
-
import { join } from "node:path";
|
|
4
|
-
import { afterEach, beforeEach, describe, expect, test, vi } from "vitest";
|
|
5
|
-
import { cmdSetup, validateModel } from "../commands/setup.js";
|
|
6
|
-
|
|
7
|
-
describe("validateModel", () => {
|
|
8
|
-
const BASE_URL = "https://api.example.com/v1";
|
|
9
|
-
const API_KEY = "sk-test-key";
|
|
10
|
-
const MODEL = "test-model";
|
|
11
|
-
|
|
12
|
-
afterEach(() => {
|
|
13
|
-
vi.restoreAllMocks();
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
test("success path — returns ok on 200", async () => {
|
|
17
|
-
const mockFetch = vi
|
|
18
|
-
.spyOn(globalThis, "fetch")
|
|
19
|
-
.mockResolvedValue(new Response(JSON.stringify({}), { status: 200 }));
|
|
20
|
-
|
|
21
|
-
const result = await validateModel(BASE_URL, API_KEY, MODEL);
|
|
22
|
-
|
|
23
|
-
expect(result).toEqual({ ok: true, value: undefined });
|
|
24
|
-
expect(mockFetch).toHaveBeenCalledTimes(1);
|
|
25
|
-
|
|
26
|
-
const [url, opts] = mockFetch.mock.calls[0]!;
|
|
27
|
-
expect(url).toBe(`${BASE_URL}/chat/completions`);
|
|
28
|
-
expect((opts as RequestInit).headers).toEqual(
|
|
29
|
-
expect.objectContaining({ Authorization: `Bearer ${API_KEY}` }),
|
|
30
|
-
);
|
|
31
|
-
const body = JSON.parse((opts as RequestInit).body as string);
|
|
32
|
-
expect(body).toEqual({
|
|
33
|
-
model: MODEL,
|
|
34
|
-
messages: [{ role: "user", content: "hi" }],
|
|
35
|
-
max_tokens: 1,
|
|
36
|
-
});
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
test("HTTP 401 — returns error containing 401", async () => {
|
|
40
|
-
vi.spyOn(globalThis, "fetch").mockResolvedValue(
|
|
41
|
-
new Response("Unauthorized", { status: 401, statusText: "Unauthorized" }),
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
const result = await validateModel(BASE_URL, API_KEY, MODEL);
|
|
45
|
-
|
|
46
|
-
expect(result.ok).toBe(false);
|
|
47
|
-
if (!result.ok) {
|
|
48
|
-
expect(result.error).toContain("401");
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
test("HTTP 404 — returns error containing 404", async () => {
|
|
53
|
-
vi.spyOn(globalThis, "fetch").mockResolvedValue(
|
|
54
|
-
new Response("Not Found", { status: 404, statusText: "Not Found" }),
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
const result = await validateModel(BASE_URL, API_KEY, MODEL);
|
|
58
|
-
|
|
59
|
-
expect(result.ok).toBe(false);
|
|
60
|
-
if (!result.ok) {
|
|
61
|
-
expect(result.error).toContain("404");
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
test("network timeout — returns error mentioning timeout", async () => {
|
|
66
|
-
const err = new DOMException("signal timed out", "AbortError");
|
|
67
|
-
vi.spyOn(globalThis, "fetch").mockRejectedValue(err);
|
|
68
|
-
|
|
69
|
-
const result = await validateModel(BASE_URL, API_KEY, MODEL);
|
|
70
|
-
|
|
71
|
-
expect(result.ok).toBe(false);
|
|
72
|
-
if (!result.ok) {
|
|
73
|
-
expect(result.error.toLowerCase()).toMatch(/timeout|timed out/);
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
test("network error (DNS/connection) — returns error mentioning connectivity", async () => {
|
|
78
|
-
vi.spyOn(globalThis, "fetch").mockRejectedValue(new TypeError("fetch failed"));
|
|
79
|
-
|
|
80
|
-
const result = await validateModel(BASE_URL, API_KEY, MODEL);
|
|
81
|
-
|
|
82
|
-
expect(result.ok).toBe(false);
|
|
83
|
-
if (!result.ok) {
|
|
84
|
-
expect(result.error.toLowerCase()).toMatch(/connect|reach|network/);
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
test("request body correctness", async () => {
|
|
89
|
-
const mockFetch = vi
|
|
90
|
-
.spyOn(globalThis, "fetch")
|
|
91
|
-
.mockResolvedValue(new Response(JSON.stringify({}), { status: 200 }));
|
|
92
|
-
|
|
93
|
-
await validateModel(BASE_URL, API_KEY, "my-special-model");
|
|
94
|
-
|
|
95
|
-
const body = JSON.parse((mockFetch.mock.calls[0]![1] as RequestInit).body as string);
|
|
96
|
-
expect(body).toEqual({
|
|
97
|
-
model: "my-special-model",
|
|
98
|
-
messages: [{ role: "user", content: "hi" }],
|
|
99
|
-
max_tokens: 1,
|
|
100
|
-
});
|
|
101
|
-
});
|
|
102
|
-
});
|
|
103
|
-
|
|
104
|
-
describe("cmdSetup with validation", () => {
|
|
105
|
-
let storageRoot: string;
|
|
106
|
-
|
|
107
|
-
beforeEach(async () => {
|
|
108
|
-
storageRoot = await mkdtemp(join(tmpdir(), "uwf-setup-validate-"));
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
afterEach(async () => {
|
|
112
|
-
vi.restoreAllMocks();
|
|
113
|
-
await rm(storageRoot, { recursive: true, force: true });
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
const setupArgs = () => ({
|
|
117
|
-
provider: "testprovider",
|
|
118
|
-
baseUrl: "https://api.test.com/v1",
|
|
119
|
-
apiKey: "sk-test",
|
|
120
|
-
model: "test-model",
|
|
121
|
-
storageRoot,
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
test("includes validation result on success", async () => {
|
|
125
|
-
vi.spyOn(globalThis, "fetch").mockResolvedValue(
|
|
126
|
-
new Response(JSON.stringify({}), { status: 200 }),
|
|
127
|
-
);
|
|
128
|
-
|
|
129
|
-
const result = await cmdSetup(setupArgs());
|
|
130
|
-
|
|
131
|
-
expect(result.validation).toEqual({ ok: true, value: undefined });
|
|
132
|
-
// Config file should still be written
|
|
133
|
-
expect(result.configPath).toBeTruthy();
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
test("includes validation failure — config still saved", async () => {
|
|
137
|
-
vi.spyOn(globalThis, "fetch").mockResolvedValue(
|
|
138
|
-
new Response("Unauthorized", { status: 401, statusText: "Unauthorized" }),
|
|
139
|
-
);
|
|
140
|
-
|
|
141
|
-
const result = await cmdSetup(setupArgs());
|
|
142
|
-
|
|
143
|
-
expect(result.validation).toBeDefined();
|
|
144
|
-
expect((result.validation as { ok: boolean }).ok).toBe(false);
|
|
145
|
-
// Config file should still be written despite validation failure
|
|
146
|
-
expect(result.configPath).toBeTruthy();
|
|
147
|
-
});
|
|
148
|
-
});
|
|
File without changes
|