@skyramp/mcp 0.2.8 → 0.2.150-rc.local.de
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/build/commands/commandLibrary.d.ts +1 -0
- package/build/commands/commandLibrary.js +18 -17
- package/build/commands/localDevTestChangesCommand.d.ts +15 -0
- package/build/commands/localDevTestChangesCommand.js +175 -0
- package/build/index.js +74 -13
- package/build/prompts/enhance-assertions/sharedAssertionRules.js +1 -0
- package/build/prompts/initialize-workspace/initializeWorkspacePrompt.js +7 -6
- package/build/prompts/local-dev/local-dev-plan.d.ts +25 -0
- package/build/prompts/local-dev/local-dev-plan.js +414 -0
- package/build/prompts/local-dev/local-dev-prompts.d.ts +4 -0
- package/build/prompts/local-dev/local-dev-prompts.js +152 -0
- package/build/prompts/prompt-utils.d.ts +8 -0
- package/build/prompts/prompt-utils.js +33 -0
- package/build/prompts/sut-setup/modes/adaptWorkflowPrompt.js +3 -1
- package/build/prompts/sut-setup/modes/dockerComposePrompt.js +3 -1
- package/build/prompts/sut-setup/shared.d.ts +20 -0
- package/build/prompts/sut-setup/shared.js +69 -7
- package/build/prompts/test-recommendation/analysisOutputPrompt.js +21 -29
- package/build/prompts/test-recommendation/analysisOutputPrompt.test.js +79 -16
- package/build/prompts/test-recommendation/test-recommendation-prompt.js +41 -4
- package/build/prompts/test-recommendation/test-recommendation-prompt.test.js +34 -1
- package/build/prompts/testbot/testbot-prompts.d.ts +0 -5
- package/build/prompts/testbot/testbot-prompts.js +4 -34
- package/build/resources/testbotResource.js +2 -1
- package/build/services/TestExecutionService.d.ts +10 -2
- package/build/services/TestExecutionService.js +220 -28
- package/build/services/TestExecutionService.test.js +447 -16
- package/build/services/TestGenerationService.d.ts +2 -2
- package/build/tool-phases.js +4 -0
- package/build/tools/code-refactor/enhanceAssertionsTool.js +34 -2
- package/build/tools/enrichTestWithMocksTool.d.ts +15 -0
- package/build/tools/enrichTestWithMocksTool.js +414 -0
- package/build/tools/enrichTestWithMocksTool.test.d.ts +1 -0
- package/build/tools/enrichTestWithMocksTool.test.js +397 -0
- package/build/tools/executeSkyrampTestTool.d.ts +3 -0
- package/build/tools/executeSkyrampTestTool.js +73 -18
- package/build/tools/executeSkyrampTestTool.test.d.ts +1 -0
- package/build/tools/executeSkyrampTestTool.test.js +111 -0
- package/build/tools/generate-tests/batchMockGenerationTool.d.ts +72 -0
- package/build/tools/generate-tests/batchMockGenerationTool.js +382 -0
- package/build/tools/generate-tests/batchMockGenerationTool.test.d.ts +1 -0
- package/build/tools/generate-tests/batchMockGenerationTool.test.js +514 -0
- package/build/tools/generate-tests/generateContractRestTool.js +2 -2
- package/build/tools/generate-tests/generateMockRestTool.d.ts +56 -6
- package/build/tools/generate-tests/generateMockRestTool.js +193 -21
- package/build/tools/generate-tests/generateMockRestTool.test.d.ts +1 -0
- package/build/tools/generate-tests/generateMockRestTool.test.js +340 -0
- package/build/tools/generateEnrichedIntegrationTestTool.d.ts +24 -0
- package/build/tools/generateEnrichedIntegrationTestTool.js +209 -0
- package/build/tools/generateEnrichedIntegrationTestTool.test.d.ts +1 -0
- package/build/tools/generateEnrichedIntegrationTestTool.test.js +199 -0
- package/build/tools/one-click/oneClickTool.d.ts +10 -0
- package/build/tools/one-click/oneClickTool.js +182 -40
- package/build/tools/one-click/oneClickTool.test.d.ts +1 -0
- package/build/tools/one-click/oneClickTool.test.js +204 -0
- package/build/tools/preflightMockCheckTool.d.ts +2 -0
- package/build/tools/preflightMockCheckTool.js +91 -0
- package/build/tools/test-management/analyzeChangesTool.d.ts +2 -1
- package/build/tools/test-management/analyzeChangesTool.js +59 -38
- package/build/tools/workspace/initializeWorkspaceTool.js +2 -9
- package/build/tools/workspace/initializeWorkspaceTool.test.js +9 -4
- package/build/types/OneClickCommands.d.ts +1 -1
- package/build/types/RepositoryAnalysis.d.ts +117 -0
- package/build/types/RepositoryAnalysis.js +16 -2
- package/build/types/TestTypes.d.ts +11 -2
- package/build/types/TestTypes.js +11 -1
- package/build/utils/analyze-openapi.js +18 -1
- package/build/utils/analyze-openapi.test.d.ts +1 -0
- package/build/utils/analyze-openapi.test.js +19 -0
- package/build/utils/branchDiff.d.ts +17 -1
- package/build/utils/branchDiff.js +96 -14
- package/build/utils/branchDiff.test.d.ts +1 -0
- package/build/utils/branchDiff.test.js +107 -0
- package/build/utils/docker.test.js +1 -1
- package/build/utils/featureFlags.d.ts +15 -1
- package/build/utils/featureFlags.js +19 -2
- package/build/utils/featureFlags.test.js +57 -2
- package/build/utils/grpcMockValidation.d.ts +1 -0
- package/build/utils/grpcMockValidation.js +49 -0
- package/build/utils/grpcMockValidation.test.d.ts +1 -0
- package/build/utils/grpcMockValidation.test.js +41 -0
- package/build/utils/httpMethodValidation.d.ts +4 -0
- package/build/utils/httpMethodValidation.js +13 -0
- package/build/utils/mockCompatibility.d.ts +49 -0
- package/build/utils/mockCompatibility.js +80 -0
- package/build/utils/mockCompatibility.test.d.ts +1 -0
- package/build/utils/mockCompatibility.test.js +88 -0
- package/build/utils/versions.d.ts +3 -3
- package/build/utils/versions.js +1 -1
- package/build/workspace/workspace.d.ts +35 -21
- package/build/workspace/workspace.js +8 -4
- package/build/workspace/workspace.test.js +65 -6
- package/package.json +2 -2
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { readWorkspaceConfigRaw } from "../utils/workspaceAuth.js";
|
|
2
|
+
export function escapeXml(value) {
|
|
3
|
+
return value
|
|
4
|
+
.replaceAll("&", "&")
|
|
5
|
+
.replaceAll("<", "<")
|
|
6
|
+
.replaceAll(">", ">")
|
|
7
|
+
.replaceAll('"', """)
|
|
8
|
+
.replaceAll("'", "'");
|
|
9
|
+
}
|
|
10
|
+
export function buildServiceContext(services) {
|
|
11
|
+
const blocks = services.map((svc) => {
|
|
12
|
+
const parts = [`<service name="${escapeXml(svc.serviceName)}">`];
|
|
13
|
+
if (svc.language)
|
|
14
|
+
parts.push(` <language>${escapeXml(svc.language)}</language>`);
|
|
15
|
+
if (svc.framework)
|
|
16
|
+
parts.push(` <framework>${escapeXml(svc.framework)}</framework>`);
|
|
17
|
+
if (svc.api?.baseUrl)
|
|
18
|
+
parts.push(` <base_url>${escapeXml(svc.api.baseUrl)}</base_url>`);
|
|
19
|
+
if (svc.testDirectory)
|
|
20
|
+
parts.push(` <test_directory>${escapeXml(svc.testDirectory)}</test_directory>`);
|
|
21
|
+
parts.push("</service>");
|
|
22
|
+
return parts.join("\n");
|
|
23
|
+
});
|
|
24
|
+
return `<services>\n${blocks.join("\n")}\n</services>`;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Read services from .skyramp/workspace.yml. Returns empty array if
|
|
28
|
+
* the workspace file doesn't exist or can't be parsed.
|
|
29
|
+
*/
|
|
30
|
+
export async function readWorkspaceServices(repositoryPath) {
|
|
31
|
+
const rawConfig = await readWorkspaceConfigRaw(repositoryPath);
|
|
32
|
+
return (rawConfig?.services ?? []);
|
|
33
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { TESTBOT_WORKFLOW_PATH, buildContextBlock, buildCommonSutErrorsSection, buildLocalValidationSection, buildInputsBody, buildSutDefinitionBlock, } from "../shared.js";
|
|
1
|
+
import { TESTBOT_WORKFLOW_PATH, buildContextBlock, buildCommonSutErrorsSection, buildLocalValidationSection, buildInputsBody, buildSeedDataDiscoverySection, buildSutDefinitionBlock, buildWorkspaceInitSection, } from "../shared.js";
|
|
2
2
|
import { getPersonaPrefix } from "../../personas.js";
|
|
3
3
|
import { PromptPlan } from "../../test-recommendation/promptPlan.js";
|
|
4
4
|
// ── Step body builders ────────────────────────────────────────────────────────
|
|
@@ -70,6 +70,7 @@ function buildAdaptRestrictionsBody() {
|
|
|
70
70
|
// ── PromptPlan declaration ────────────────────────────────────────────────────
|
|
71
71
|
const _adaptPlan = new PromptPlan()
|
|
72
72
|
.addPhase("adapt", "", { headerLevel: "hidden", stepFormat: "hash" })
|
|
73
|
+
.step("INIT_WORKSPACE", "Initialise the Skyramp workspace file", () => buildWorkspaceInitSection())
|
|
73
74
|
.step("SCAN", "Understand the System Under Test in this repository", () => "")
|
|
74
75
|
.subStep("READ_SOURCES", "Read workflows and infra files", buildReadSourcesBody)
|
|
75
76
|
.subStep("CLASSIFY_STEPS", "Classify source workflow steps", buildClassifyStepsBody)
|
|
@@ -80,6 +81,7 @@ const _adaptPlan = new PromptPlan()
|
|
|
80
81
|
.subStep("PATTERN_C", "Pattern C — GHA steps replace service startup + Testbot lifecycle validation", buildPatternCBody)
|
|
81
82
|
.subStep("PATTERN_D", "Pattern D — Fully wrapped by GHA steps", buildPatternDBody)
|
|
82
83
|
.step("INPUTS", "Plan the Testbot action inputs", () => buildInputsBody())
|
|
84
|
+
.step("SEED_DATA", "Discover database seed-data conventions", () => buildSeedDataDiscoverySection())
|
|
83
85
|
.step("ADAPT", "Edit the Testbot workflow and generate SUT files", () => "")
|
|
84
86
|
.subStep("EDIT_WORKFLOW", "Edit the workflow file", buildEditWorkflowBody)
|
|
85
87
|
.subStep("CONFIGURE_AUTH", "Configure auth", buildConfigureAuthBody)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { buildContextBlock, buildInputsBody, buildCommonSutErrorsSection, buildLocalValidationSection, buildSutDefinitionBlock, } from "../shared.js";
|
|
1
|
+
import { buildContextBlock, buildInputsBody, buildCommonSutErrorsSection, buildLocalValidationSection, buildSeedDataDiscoverySection, buildSutDefinitionBlock, buildWorkspaceInitSection, } from "../shared.js";
|
|
2
2
|
import { getPersonaPrefix } from "../../personas.js";
|
|
3
3
|
import { PromptPlan } from "../../test-recommendation/promptPlan.js";
|
|
4
4
|
// ── Step body builders ────────────────────────────────────────────────────────
|
|
@@ -260,9 +260,11 @@ ${GENERATE_DOCKER_COMPOSE_INSTRUCTIONS}`;
|
|
|
260
260
|
// ── PromptPlan declaration ────────────────────────────────────────────────────
|
|
261
261
|
const _composePlan = new PromptPlan()
|
|
262
262
|
.addPhase("compose", "", { headerLevel: "hidden", stepFormat: "hash" })
|
|
263
|
+
.step("INIT_WORKSPACE", "Initialise the Skyramp workspace file", () => buildWorkspaceInitSection())
|
|
263
264
|
.step("SCAN", "Understand the System Under Test in this repository", buildScanComposeBody)
|
|
264
265
|
.step("DECIDE", "Decide SUT setup strategy", buildDecideStrategyBody)
|
|
265
266
|
.step("INPUTS", "Plan the Testbot action inputs", () => buildInputsBody())
|
|
267
|
+
.step("SEED_DATA", "Discover database seed-data conventions", () => buildSeedDataDiscoverySection())
|
|
266
268
|
.step("BUILD", "Edit the Testbot workflow and generate SUT files", () => "")
|
|
267
269
|
.subStep("PR_ACCURATE", "Build PR-accurate SUT", buildPrAccurateSutSection)
|
|
268
270
|
.subStep("APPLY", "Apply the chosen strategy", buildApplyStrategyBody)
|
|
@@ -21,6 +21,26 @@ export interface SutPromptArgs {
|
|
|
21
21
|
*/
|
|
22
22
|
export declare function buildSutDefinitionBlock(): string;
|
|
23
23
|
export declare function buildContextBlock(args: SutPromptArgs): string;
|
|
24
|
+
/**
|
|
25
|
+
* Seed-data discovery block — rendered as a SUT-bootstrap step so the agent
|
|
26
|
+
* looks for existing customer seed conventions BEFORE inventing new ones.
|
|
27
|
+
* A fresh database makes list / search / filter / pagination endpoint tests
|
|
28
|
+
* shallow (only HTTP-status assertable, never response content), which
|
|
29
|
+
* collapses the data-diversity dimension of the eval. Most repos already
|
|
30
|
+
* have a seed mechanism — wire that in instead of generating one.
|
|
31
|
+
*
|
|
32
|
+
* Rendered as a top-level PromptPlan step between INPUTS and the
|
|
33
|
+
* ADAPT/BUILD step in every SUT setup mode.
|
|
34
|
+
*/
|
|
35
|
+
export declare function buildSeedDataDiscoverySection(): string;
|
|
36
|
+
/**
|
|
37
|
+
* Workspace file initialisation block — rendered as the first instruction
|
|
38
|
+
* in every SUT setup mode, before any local validation, workflow editing,
|
|
39
|
+
* or SUT-file generation. Seeds `.skyramp/workspace.yml` with the service
|
|
40
|
+
* inventory so testbot's SUT autocommit picks it up alongside the
|
|
41
|
+
* generated `.skyramp/sut/*` files.
|
|
42
|
+
*/
|
|
43
|
+
export declare function buildWorkspaceInitSection(): string;
|
|
24
44
|
export declare function buildLocalValidationSection(): string;
|
|
25
45
|
/**
|
|
26
46
|
* Returns the canonical "add to the Testbot workflow" block: every input that
|
|
@@ -31,6 +31,59 @@ export function buildContextBlock(args) {
|
|
|
31
31
|
lines.push(`</context>`);
|
|
32
32
|
return lines.join("\n");
|
|
33
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Seed-data discovery block — rendered as a SUT-bootstrap step so the agent
|
|
36
|
+
* looks for existing customer seed conventions BEFORE inventing new ones.
|
|
37
|
+
* A fresh database makes list / search / filter / pagination endpoint tests
|
|
38
|
+
* shallow (only HTTP-status assertable, never response content), which
|
|
39
|
+
* collapses the data-diversity dimension of the eval. Most repos already
|
|
40
|
+
* have a seed mechanism — wire that in instead of generating one.
|
|
41
|
+
*
|
|
42
|
+
* Rendered as a top-level PromptPlan step between INPUTS and the
|
|
43
|
+
* ADAPT/BUILD step in every SUT setup mode.
|
|
44
|
+
*/
|
|
45
|
+
export function buildSeedDataDiscoverySection() {
|
|
46
|
+
return `**First, decide if this step applies.** Skip it entirely (in your summary state \`SEED_DATA: N/A — <reason>\`, naming the specific bullet below that applied — e.g. "no stateful service", "no list endpoints in scope", "already seeded by init container") and move on when ANY of the following is true:
|
|
47
|
+
- The SUT has no database / stateful service (it's a pure stateless API, a static asset server, a webhook receiver, etc.).
|
|
48
|
+
- The compose stack contains no database container (no \`postgres\`, \`mysql\`, \`mariadb\`, \`mongodb\`, \`redis\` as the primary store, \`sqlite\`, etc.) and no application-managed persistent store.
|
|
49
|
+
- The PR diff and the existing test surface focus exclusively on auth, single-resource CRUD (POST/GET-one/PUT/DELETE on \`/foo/{id}\`), or compute endpoints — no list / search / filter / pagination / aggregate endpoints will be exercised.
|
|
50
|
+
- You can confirm from the SCAN step's findings that representative records already exist (e.g. seeded by an init container, by a migration, or by the auth/setup flow you already wired).
|
|
51
|
+
|
|
52
|
+
Only proceed with the rest of this step when the SUT has a database AND the tests will exercise list/search/filter/pagination endpoints. Otherwise an empty database is acceptable and inventing seed data adds noise.
|
|
53
|
+
|
|
54
|
+
When this step DOES apply: database services usually start empty in CI, so tests against list / search / filter / pagination endpoints will then only see \`[]\` and can assert nothing beyond HTTP status — a low data-diversity outcome. Look for an existing seeding mechanism in the repo and wire it into the SUT bootstrap.
|
|
55
|
+
|
|
56
|
+
**Discover existing project conventions first** — most repos already have one of:
|
|
57
|
+
1. A named script: \`scripts/seed*\`, \`db/seeds/*\`, \`prisma/seed.{ts,js}\`, \`apps/api/seed/*\`, \`tests/fixtures/seed*\`. Search: \`find . -iname '*seed*' -not -path '*/node_modules/*' -not -path '*/.git/*'\`.
|
|
58
|
+
2. A package.json / Makefile target: \`npm run seed\`, \`npm run db:seed\`, \`pnpm seed\`, \`yarn seed\`, \`make seed\`, \`make fixtures\`. Check \`package.json\` \`scripts\` and the project's \`Makefile\`.
|
|
59
|
+
3. A migration with sample data: Django \`loaddata\`, Rails \`db:seed\`, Knex \`seed:run\`, Prisma \`db seed\`, Alembic data migrations.
|
|
60
|
+
4. A docker-compose init service: existing compose files sometimes have a \`*-seed\`, \`*-fixtures\`, or \`init-*\` service that runs once on bring-up.
|
|
61
|
+
|
|
62
|
+
**Wire it in:**
|
|
63
|
+
- **Compose init service** — add it (or its dependency) to the testbot compose so \`targetSetupCommand\` brings it up alongside the rest. Use \`depends_on\` with \`condition: service_completed_successfully\` on dependent services so they only start after seeding finishes.
|
|
64
|
+
- **Script needing an admin/API token** (most common) — chain it INTO \`authTokenCommand\` AFTER the token is created and BEFORE the script prints the token to stdout. Route seed stdout/stderr to stderr so the captured token isn't corrupted. Make the seed call best-effort (\`|| echo "seed failed" >&2\`) so a flaky seed doesn't block the run — the token is still returned and PRs whose tests don't need seed data keep working.
|
|
65
|
+
- **Migration with sample data** — ensure the migration runs as part of \`targetSetupCommand\` (some ORMs auto-run on container start, others need an explicit \`migrate\` / \`db:seed\` step before tests can hit the API).
|
|
66
|
+
|
|
67
|
+
**If NO existing convention is found**, generate a minimal seed step (≥3 entities per primary resource the tests will query, e.g., ≥3 repos / ≥3 issues / ≥3 users for a forge; ≥3 products / ≥3 orders for a shop). Call this out explicitly in your summary so the user knows a richer fixture may be needed for production-quality tests.
|
|
68
|
+
|
|
69
|
+
**Never** hard-code production data, real customer credentials, or PII in seeds. Seed identifiers should be obviously test-only (\`acme-co\`, \`alpha-svc\`, \`testbot-admin\`).`;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Workspace file initialisation block — rendered as the first instruction
|
|
73
|
+
* in every SUT setup mode, before any local validation, workflow editing,
|
|
74
|
+
* or SUT-file generation. Seeds `.skyramp/workspace.yml` with the service
|
|
75
|
+
* inventory so testbot's SUT autocommit picks it up alongside the
|
|
76
|
+
* generated `.skyramp/sut/*` files.
|
|
77
|
+
*/
|
|
78
|
+
export function buildWorkspaceInitSection() {
|
|
79
|
+
return `Before generating any SUT setup files, check whether \`.skyramp/workspace.yml\` exists at the root of the repository being bootstrapped (the path shown next to "Repository path:" in the context block above — the repo whose PR triggered Testbot; in multi-repo runs this is the primary repo, not the sibling repos checked out as related repos). If it doesn't:
|
|
80
|
+
1. Call \`skyramp_init_scan\` with \`workspacePath\` set to that repository root → follow the returned instructions to discover all services.
|
|
81
|
+
2. Call \`skyramp_init_workspace\` with the same \`workspacePath\`, \`services\`, and the \`scanToken\` from step 1.
|
|
82
|
+
|
|
83
|
+
This produces a baseline \`.skyramp/workspace.yml\` listing the services Testbot will test. Later steps in this SUT bootstrap run write \`.skyramp/sut/*\` files alongside it. You might have to update the per-service \`runtimeDetails.serverStartCommand\` to match the new SUT files created, so Testbot brings up the services correctly.
|
|
84
|
+
|
|
85
|
+
Also verify each service's \`api.baseUrl\` includes the API path prefix (e.g. \`/api\`, \`/api/v1\`, \`/v1\`) — not just \`host:port\`. A bare host means every test request hits the root and 404s. Derive the prefix from the strongest available signal: OpenAPI \`servers[].url\` or \`basePath\`; the app's routing config (FastAPI \`root_path\`, Express \`app.use('/api/v1', ...)\`, Rails routes prefix, Django \`urlpatterns\` mount); or the longest common leading path across the existing test suite's endpoints. If none of those yield a prefix, leave it bare AND flag it in your summary so the user can review.`;
|
|
86
|
+
}
|
|
34
87
|
export function buildLocalValidationSection() {
|
|
35
88
|
return `Before reporting success, exercise the adapted workflow locally. Testbot's external fix loop only retries when SUT lifecycle commands are set on the Testbot action. When the SUT is brought up by surrounding GHA steps (skipTargetSetup: 'true'), the fix loop is skipped — so the local check below is the only safety net before the workflow is committed.
|
|
36
89
|
Run commands one at a time in your shell — individual execution pinpoints failures far faster than running the whole workflow at once. Any non-zero exit is a fix-needed signal: adjust the workflow, re-run the failing command, and do not proceed until it passes.
|
|
@@ -39,7 +92,7 @@ Run commands one at a time in your shell — individual execution pinpoints fail
|
|
|
39
92
|
b. \`.skyramp/sut/get-auth-token.sh\` if present — run it and confirm it prints a non-empty token to stdout.
|
|
40
93
|
c. Validate any standalone Dockerfile referenced by GHA \`steps:\` (not by a compose service) with \`docker build\`. Do NOT also run \`docker build\` on Dockerfiles that belong to a compose service — \`docker compose build\` (next step) already builds them in one BuildKit graph; doubling up wastes ~5-10 GB of cache per service.
|
|
41
94
|
d. Every docker-compose file the workflow references — run \`docker compose -f <path> config\` to validate the YAML, then \`docker compose -f <path> build\`.
|
|
42
|
-
e. **Disk hygiene between heavy builds.** Between any two build commands (Dockerfile, compose, helper scripts that build), if the runner is under ~5 GB free or you see \`no space left on device\`,
|
|
95
|
+
e. **Disk hygiene between heavy builds.** Between any two build commands (Dockerfile, compose, helper scripts that build), if the runner is under ~5 GB free or you see \`no space left on device\`, prune docker BuildKit cache and dangling images before the next build (keep the running stack intact). Skipping this on heavy SUTs exhausts the standard runner disk mid-validation.
|
|
43
96
|
2. Validate the SUT lifecycle — choose the branch that matches the chosen pattern:
|
|
44
97
|
a. If lifecycle commands are set on the Testbot action (skipTargetSetup is unset):
|
|
45
98
|
i. Run \`targetSetupCommand\` — confirm exit 0.
|
|
@@ -68,8 +121,16 @@ Target lifecycle inputs (control how Testbot starts, validates, and stops the SU
|
|
|
68
121
|
b. For PR-source builds use \`docker compose up -d --build\` or the equivalent for helm/script-based SUTs.
|
|
69
122
|
c. With a dedicated compose file (reused or generated), point at it explicitly: \`docker compose -f .skyramp/sut/docker-compose.testbot.yml --project-directory . up -d --build\`.
|
|
70
123
|
d. Override whenever the source workflow's start sequence differs from the default.
|
|
71
|
-
2. \`targetReadyCheckCommand\` — polling command
|
|
72
|
-
a. **CRITICAL:
|
|
124
|
+
2. \`targetReadyCheckCommand\` — polling command Testbot runs repeatedly after setup until it exits 0 (service ready) or the timeout fires.
|
|
125
|
+
a. **CRITICAL: must cover EVERY service the tests will hit, not just the backend.** Chain checks with \`&&\` so the command exits 0 only when ALL services respond. A single-service check on a multi-service SUT is the leading cause of "element not visible" / "heading not visible" UI test failures — Playwright lands on a partially-rendered page because only the API was up when the gate passed. Inventory of services to include:
|
|
126
|
+
- Every API service in workspace.yml with an \`api.baseUrl\` → curl an unauthenticated endpoint (health / version / status).
|
|
127
|
+
- Every UI service with a UI \`baseUrl\` (or a frontend port in compose) → curl \`/\` or a known asset like \`/assets/index.js\` (more reliable than \`/\` for SPAs that hydrate lazily).
|
|
128
|
+
- Skip auth-required endpoints — they 401 before the SUT is testable and mask the readiness signal.
|
|
129
|
+
Examples:
|
|
130
|
+
- API only: \`curl -sf http://localhost:8080/api/health\`
|
|
131
|
+
- API + UI: \`curl -sf http://localhost:8080/api/health && curl -sf http://localhost:3000/\`
|
|
132
|
+
Required in every pattern (explicit \`targetSetupCommand\`, the \`docker compose up -d\` default, AND \`skipTargetSetup: 'true'\`). Without a real readiness signal (neither this nor a workspace service \`baseUrl\`), testbot's fail-early gate throws \`Unable to verify service readiness\` and the action exits non-zero. It is also what gates a backgrounded \`targetSetupCommand\` — without it Testbot can't tell when the service is actually listening.
|
|
133
|
+
b. Set \`targetReadyCheckDiagnosticsCommand\` to a command that explains why the SUT isn't healthy — output is surfaced in the failure PR comment when the ready check times out. For docker-compose SUTs, scope it to the project's compose file (container state + recent service logs). For non-docker SUTs, a tail of the server log.
|
|
73
134
|
3. \`targetReadyCheckTimeout\` — seconds to wait for \`targetReadyCheckCommand\` to succeed.
|
|
74
135
|
a. Default: \`1800\` (30 min) — sized for cold \`docker compose --build\` runs on multi-service stacks. The loop exits on the first success, so fast services pay no extra cost. Override only if you want to fail faster on stuck setups (e.g. \`'300'\` for a small single-service SUT).
|
|
75
136
|
4. \`targetTeardownCommand\` — shell command that stops and cleans up the SUT after tests (e.g., \`docker compose down -v\`, or \`docker compose -f .skyramp/sut/docker-compose.testbot.yml --project-directory . down -v\` for a dedicated compose file).
|
|
@@ -89,19 +150,20 @@ Auth inputs (used by Testbot to authenticate against the running SUT during test
|
|
|
89
150
|
b. Use \`\${{ secrets.SKYRAMP_UI_CREDENTIALS }}\` if the secret exists, otherwise use credentials seeded during SUT setup.
|
|
90
151
|
Workflow / job level settings (set on the workflow or job, not as \`skyramp/testbot\` action inputs):
|
|
91
152
|
8. Secrets / environment variables — pass every secret/env var the setup needs into the workflow via an \`env:\` block or \`secrets: inherit\`, and add any dependency-resolution steps/jobs the SUT requires.
|
|
92
|
-
9. \`runs-on\` runner label —
|
|
153
|
+
9. \`runs-on\` runner label — leave whatever value the Testbot installer wrote and the source workflow used. Don't override it. Picking a runner SKU is an account-level decision that depends on provisioning the agent can't see from inside the repo; a wrong choice queues the job forever with no runner ever picking it up. If the SUT genuinely doesn't fit on the chosen runner, the disk-pressure mitigation in "Common failure modes" #9 handles it; an unprovisioned-runner stall does not.
|
|
93
154
|
|
|
94
155
|
#### What to do
|
|
95
156
|
Edit \`${TESTBOT_WORKFLOW_PATH}\` in place (already created by the Testbot installer) — do NOT recreate it. Add only what the SUT needs onto the existing \`skyramp/testbot\` action step, alongside the inputs the installer already added:
|
|
96
157
|
1. The 4 target lifecycle inputs — \`targetSetupCommand\`, \`targetReadyCheckCommand\`, \`targetReadyCheckTimeout\`, \`targetTeardownCommand\`.
|
|
97
158
|
2. The 2 auth inputs when the SUT needs them — \`authTokenCommand\` and/or \`uiCredentials\`.
|
|
98
159
|
3. Any secrets / environment variables and dependency-resolution steps/jobs the setup needs (input 8).
|
|
99
|
-
4.
|
|
160
|
+
4. Leave the existing \`runs-on\` value untouched (input 9).
|
|
100
161
|
5. Use a daemon/detached form for \`targetSetupCommand\` — \`docker compose up -d --build\`, \`nohup npm start &\`, \`./server &\`, \`pnpm --prefix ./apps/studio start &\`. The command should launch the service and exit; \`targetReadyCheckCommand\` is what gates readiness. Testbot backgrounds foreground-blocking commands (\`npm start\`, \`python app.py\`, \`./server\`) automatically after a 5-minute timeout as a safety net, so they will eventually work — but daemon mode is faster (no 5-minute wait) and surfaces startup crashes clearly via the command's exit code. If no daemon form is available and the repo has no \`docker-compose.yml\`, wrap the foreground command in compose (a \`Dockerfile\` + \`docker-compose.yml\` running \`npm start\`) so it can be launched with \`docker compose up -d --build\`. Only fall back to a GHA pre-step with \`&\` (e.g. \`run: npm start &\`) if Docker is not feasible.
|
|
162
|
+
6. Stack-specific testability flags — some frameworks gate test-harness affordances behind a container env var. Common cases: Flutter web needs \`IS_TESTING=true\` so \`ensureSemantics()\` exposes the widget tree to Playwright (without it every selector finds nothing even though the app is up); some React/Angular builds need \`NODE_ENV\` / framework-specific build flags for \`testID\` propagation. Set these in the compose \`environment:\` block on the affected service (or as a \`Dockerfile ENV\`) — NOT as a shell var in \`targetSetupCommand\`. The var must be in the container's env at boot, not just the shell that runs the setup command. If selectors find nothing but the app is up, check for a missing flag like this first.
|
|
101
163
|
|
|
102
164
|
#### What not to do
|
|
103
165
|
1. IMPORTANT — do NOT remove or change the existing \`sutSetupMode\` input (nor \`sutSourceWorkflowFile\` / \`sutSourceDockerComposeFile\`). Leave \`sutSetupMode\` exactly as provided: Testbot flips it to \`none\` automatically after validation succeeds, and the committed \`sutSetupMode\` value is the signal that tells the next CI run to validate this adapted workflow rather than run tests. Deleting it or setting it to \`none\` breaks the bootstrap/validation cycle.
|
|
104
|
-
2. Do not point the SUT at a prebuilt upstream image (e.g. \`image: org/app:latest\` or a fixed commit SHA from \`main\`) for any application service under test. The image will lag the PR and Testbot will validate stale code.
|
|
166
|
+
2. Do not point the SUT at a prebuilt upstream image (e.g. \`image: org/app:latest\` or a fixed commit SHA from \`main\`) for any application service under test. The image will lag the PR and Testbot will validate stale code. In case of multi-mode containers (\`Dockerfile.bdd\`, \`Dockerfile.e2e\`, \`Dockerfile.integration\`, \`Dockerfile.test\`), create the necessary file in \`.skyramp/sut/\` with a PR-sourced build (e.g. \`.skyramp/sut/Dockerfile.bdd\` referenced from the testbot compose's \`build:\`). Do not edit existing Dockerfiles or compose files in the repo. If the multi-mode container's bootstrap step depends on a seeded user, ensure SEED_DATA creates it before this container tries to log in.
|
|
105
167
|
3. Do not point the SUT at a remote staging or production environment for application services under test. Staging code drifts from PR source and turns Testbot's results into noise. External infra is acceptable only for sidecar dependencies the PR does not change (e.g. a managed test database).
|
|
106
168
|
4. Do not use a foreground-blocking command as \`targetSetupCommand\` (e.g. \`npm start\`, \`pnpm --prefix ./apps/studio start\`, \`python app.py\`, \`prefect server start\`, \`./server\`) — see input 5 in "What to do" above for daemon forms and the compose-wrap fallback.
|
|
107
169
|
5. Do not leave server processes running between fix-loop retries. If \`targetSetupCommand\` starts a direct process (not \`docker compose\`), always set \`targetTeardownCommand\` to kill it (e.g. \`pkill -f "node dist/index.js"\` or \`docker compose down\`). Without teardown, retried setup attempts will fail with \`EADDRINUSE\` because the previous process still holds the port.
|
|
@@ -127,6 +189,6 @@ export function buildCommonSutErrorsSection() {
|
|
|
127
189
|
6. permission_denied — script is not executable (\`chmod +x\`) or volume mount has wrong ownership.
|
|
128
190
|
7. auth_endpoint_404 / auth_credentials_invalid — the auth script hits a wrong path, or the database has no seeded user. The auth script must create the user before login when starting from a fresh DB.
|
|
129
191
|
8. missing env vars / secrets — required env vars are unset on the runner. Either default them in the script or pass them through workflow \`env:\`.
|
|
130
|
-
9. no_space_left — the runner ran out of disk space (\`No space left on device\`).
|
|
192
|
+
9. no_space_left — the runner ran out of disk space (\`No space left on device\`). Prune the docker BuildKit cache and dangling images at the start of both \`targetSetupCommand\` and \`targetTeardownCommand\` so each fix-loop retry begins with a clean slate; without it, cache from the previous attempt accumulates across retries on heavy SUTs. Do not change \`runs-on\` — see input 9 above.
|
|
131
193
|
Do not add an in-prompt fix loop — Testbot's external validator will retry with concrete error context if any of these occur.`;
|
|
132
194
|
}
|
|
@@ -288,11 +288,11 @@ The ranked test recommendation catalog is pre-built and shown below (after the s
|
|
|
288
288
|
**If** Steps 1–2 revealed additional scenarios the catalog does not cover (e.g. a computed formula or foreign-key relationship that was missed), you may optionally call \`skyramp_recommend_tests\` with \`stateFile: "${p.stateFile ?? p.sessionId}"\` and \`enrichedScenarios\` to regenerate a more complete catalog — but only after presenting the current one.`;
|
|
289
289
|
const hasJavaFiles = p.candidateRouteFiles?.some((f) => /\.(java|kt)$/.test(f)) ?? false;
|
|
290
290
|
const routeFilesSection = p.candidateRouteFiles && p.candidateRouteFiles.length > 0
|
|
291
|
-
? `\
|
|
291
|
+
? `\nCandidate route/controller files for LLM inspection (read these to discover endpoints; static parser output is only a hint):\n${p.candidateRouteFiles.map((f) => `- ${f}`).join("\n")}\n`
|
|
292
292
|
: "";
|
|
293
293
|
const resolvePathsNote = p.routerMountContext.length
|
|
294
|
-
? `**Resolve nested paths** using your Step ${ANALYSIS_STEP_RESOLVE_PATHS} table
|
|
295
|
-
: `**Resolve full paths** using the prefixes you
|
|
294
|
+
? `**Resolve nested paths** using your Step ${ANALYSIS_STEP_RESOLVE_PATHS} table. The table you build from source/router context is authoritative over static parser hints.`
|
|
295
|
+
: `**Resolve full paths** using the prefixes, mounts, annotations, decorators, or routing DSL you identify in Step ${ANALYSIS_STEP_READ_FILES}.`;
|
|
296
296
|
return `## Your Task — Fill in and Present the Catalog (full repo)
|
|
297
297
|
|
|
298
298
|
### Step ${ANALYSIS_STEP_READ_FILES}: Read key files
|
|
@@ -335,36 +335,28 @@ ${p.routerFileContents?.length
|
|
|
335
335
|
p.routerMountContext.map((f) => `- \`${f}\``).join("\n")}`
|
|
336
336
|
: "";
|
|
337
337
|
const enrichment = buildEnrichmentInstructions(p);
|
|
338
|
-
|
|
339
|
-
const
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
: "The heuristic endpoint scanner found **0 endpoints**";
|
|
343
|
-
const scannerFallbackInstruction = scannerFallbackHasCatalog
|
|
344
|
-
? "Treat this as a supplemental gap check: merge only HTTP endpoints that are visibly missing from the existing catalog/spec data, and keep the existing catalog as the primary endpoint source."
|
|
345
|
-
: "Build a table of discovered endpoints (method, full path, source file) and use it as the authoritative endpoint list for all subsequent steps.";
|
|
346
|
-
const llmFallbackSection = (isDiffScope || p.scannedEndpoints.length === 0) &&
|
|
347
|
-
p.candidateRouteFiles &&
|
|
348
|
-
p.candidateRouteFiles.length > 0
|
|
338
|
+
const staticHintCount = p.scannedEndpoints.length;
|
|
339
|
+
const routeDiscoverySection = isDiffScope ||
|
|
340
|
+
staticHintCount > 0 ||
|
|
341
|
+
(p.candidateRouteFiles?.length ?? 0) > 0
|
|
349
342
|
? `
|
|
350
|
-
##
|
|
343
|
+
## LLM Route Discovery Inputs
|
|
351
344
|
|
|
352
|
-
|
|
345
|
+
Static endpoint scan results are **best-effort hints only**. Do not assume the scanner supports this repository's language, framework, routing DSL, or helper abstractions.
|
|
353
346
|
|
|
354
|
-
|
|
347
|
+
${staticHintCount > 0 ? `Static hints available: ${staticHintCount}. Verify every hinted method/path against source before using it.` : "Static hints available: 0. Build the endpoint list from source, router context, spec, and diff."}
|
|
355
348
|
|
|
356
|
-
${p.candidateRouteFiles
|
|
357
|
-
|
|
349
|
+
${p.candidateRouteFiles && p.candidateRouteFiles.length > 0
|
|
350
|
+
? `Candidate files to inspect:\n${p.candidateRouteFiles
|
|
351
|
+
.slice(0, 15)
|
|
352
|
+
.map((f) => `- \`${f}\``)
|
|
353
|
+
.join("\n")}${p.candidateRouteFiles.length > 15 ? `\n_(${p.candidateRouteFiles.length - 15} more files not shown)_` : ""}`
|
|
354
|
+
: staticHintCount > 0
|
|
355
|
+
? "Candidate files to inspect: none identified by static scanning. Verify the static hints against their source files, changed files, router context, and specs above."
|
|
356
|
+
: "Candidate files to inspect: use the changed files and routing entry-point files above."}
|
|
358
357
|
|
|
359
|
-
For each file,
|
|
360
|
-
|
|
361
|
-
- FastAPI/Flask: \`@router.<method>('/path')\` or \`@app.route('/path', ...)\`
|
|
362
|
-
- Spring/NestJS: \`@GetMapping\`, \`@PostMapping\`, \`@Controller\`, etc.
|
|
363
|
-
- Go (Gin/Echo/Chi): \`r.GET("/path", ...)\`, \`r.Group("/prefix")\`
|
|
364
|
-
- GraphQL: schema/resolver artifacts are unsupported for REST test generation; do not invent REST endpoints from them
|
|
365
|
-
- Any other framework-specific route registration pattern
|
|
366
|
-
|
|
367
|
-
${scannerFallbackInstruction}`
|
|
358
|
+
For each candidate file, infer route registrations from the source's actual framework or DSL. Record method, full path, and source file. Resolve mount prefixes through the routing entry-point files. If a file is GraphQL-only, do not invent REST endpoints from it.
|
|
359
|
+
`
|
|
368
360
|
: "";
|
|
369
361
|
return `# Repository Analysis
|
|
370
362
|
|
|
@@ -373,7 +365,7 @@ ${scannerFallbackInstruction}`
|
|
|
373
365
|
**Analysis Scope**: \`${p.analysisScope}\`
|
|
374
366
|
${isDiffScope ? `**Diff endpoints**: ${(p.parsedDiff?.newEndpoints.length ?? 0) + (p.parsedDiff?.modifiedEndpoints.length ?? 0) + (p.parsedDiff?.removedEndpoints?.length ?? 0)}` : `**Pre-scanned endpoints**: ${p.scannedEndpoints.length}`}
|
|
375
367
|
${routerSection}
|
|
376
|
-
${
|
|
368
|
+
${routeDiscoverySection}
|
|
377
369
|
${enrichment}
|
|
378
370
|
|
|
379
371
|
**CRITICAL**: No .json/.md file creation. Prioritize cross-resource workflows.`;
|
|
@@ -99,7 +99,10 @@ describe("buildAnalysisOutputText — unmatchedFiles / trace-callers sub-step",
|
|
|
99
99
|
});
|
|
100
100
|
it("lists each unmatched file as a bullet in the trace-callers block", () => {
|
|
101
101
|
const params = baseParams({
|
|
102
|
-
unmatchedFiles: [
|
|
102
|
+
unmatchedFiles: [
|
|
103
|
+
"src/services/OrderService.ts",
|
|
104
|
+
"src/utils/pricingHelper.ts",
|
|
105
|
+
],
|
|
103
106
|
});
|
|
104
107
|
const output = buildAnalysisOutputText(params);
|
|
105
108
|
expect(output).toContain("- `src/services/OrderService.ts`");
|
|
@@ -139,12 +142,21 @@ describe("buildAnalysisOutputText — unmatchedFiles / trace-callers sub-step",
|
|
|
139
142
|
});
|
|
140
143
|
it("critical-patterns checklist is present in Step 2 regardless of diff availability (phase 4b)", () => {
|
|
141
144
|
// Step 2.5 was merged into Step 2 — patterns appear inline in ALL diff-scope branches.
|
|
142
|
-
const withDiff = baseParams({
|
|
143
|
-
|
|
145
|
+
const withDiff = baseParams({
|
|
146
|
+
unmatchedFiles: ["src/utils/foo.ts"],
|
|
147
|
+
diffFilePath: "/tmp/pr.diff",
|
|
148
|
+
});
|
|
149
|
+
const withDiffNoUnmatched = baseParams({
|
|
150
|
+
unmatchedFiles: [],
|
|
151
|
+
diffFilePath: "/tmp/pr.diff",
|
|
152
|
+
});
|
|
144
153
|
const noDiff = baseParams({ unmatchedFiles: [] });
|
|
145
154
|
const uiOnly = baseParams({
|
|
146
155
|
parsedDiff: {
|
|
147
|
-
changedFiles: [
|
|
156
|
+
changedFiles: [
|
|
157
|
+
"src/components/Cart.tsx",
|
|
158
|
+
"src/components/OrderList.vue",
|
|
159
|
+
],
|
|
148
160
|
newEndpoints: [],
|
|
149
161
|
modifiedEndpoints: [],
|
|
150
162
|
},
|
|
@@ -234,31 +246,82 @@ describe("buildAnalysisOutputText — unmatchedFiles / trace-callers sub-step",
|
|
|
234
246
|
expect(output).toContain("Trace callers of changed non-route files");
|
|
235
247
|
});
|
|
236
248
|
});
|
|
237
|
-
describe("buildAnalysisOutputText —
|
|
238
|
-
it("
|
|
249
|
+
describe("buildAnalysisOutputText — LLM route discovery inputs", () => {
|
|
250
|
+
it("labels static endpoint data as hints and includes candidate files", () => {
|
|
239
251
|
const params = baseParams({
|
|
240
252
|
analysisScope: AnalysisScope.CurrentBranchDiff,
|
|
241
|
-
scannedEndpoints: [
|
|
253
|
+
scannedEndpoints: [
|
|
254
|
+
{ path: "/openapi-only", methods: ["GET"], sourceFile: "" },
|
|
255
|
+
],
|
|
242
256
|
candidateRouteFiles: ["src/routes/items.ts"],
|
|
243
257
|
});
|
|
244
258
|
const output = buildAnalysisOutputText(params);
|
|
245
|
-
expect(output).toContain("
|
|
246
|
-
expect(output).toContain("
|
|
259
|
+
expect(output).toContain("LLM Route Discovery Inputs");
|
|
260
|
+
expect(output).toContain("Static endpoint scan results are **best-effort hints only**");
|
|
261
|
+
expect(output).toContain("Static hints available: 1");
|
|
247
262
|
expect(output).toContain("src/routes/items.ts");
|
|
248
|
-
expect(output).toContain("
|
|
249
|
-
expect(output).toContain("
|
|
250
|
-
expect(output).not.toContain("use it as the authoritative endpoint list");
|
|
263
|
+
expect(output).toContain("Record method, full path, and source file");
|
|
264
|
+
expect(output).not.toContain("primary endpoint source");
|
|
251
265
|
});
|
|
252
|
-
it("
|
|
266
|
+
it("uses static-hint wording when no candidate route files are available", () => {
|
|
267
|
+
const params = baseParams({
|
|
268
|
+
analysisScope: AnalysisScope.FullRepo,
|
|
269
|
+
scannedEndpoints: [
|
|
270
|
+
{ path: "/openapi-only", methods: ["GET"], sourceFile: "openapi.yaml" },
|
|
271
|
+
],
|
|
272
|
+
candidateRouteFiles: [],
|
|
273
|
+
});
|
|
274
|
+
const output = buildAnalysisOutputText(params);
|
|
275
|
+
expect(output).toContain("LLM Route Discovery Inputs");
|
|
276
|
+
expect(output).toContain("Static hints available: 1");
|
|
277
|
+
expect(output).toContain("Candidate files to inspect: none identified by static scanning");
|
|
278
|
+
expect(output).not.toContain("Candidate files to inspect: use the changed files and routing entry-point files above.");
|
|
279
|
+
});
|
|
280
|
+
it("includes route discovery inputs for diff scope with zero hints or candidates", () => {
|
|
281
|
+
const params = baseParams({
|
|
282
|
+
analysisScope: AnalysisScope.CurrentBranchDiff,
|
|
283
|
+
scannedEndpoints: [],
|
|
284
|
+
candidateRouteFiles: [],
|
|
285
|
+
});
|
|
286
|
+
const output = buildAnalysisOutputText(params);
|
|
287
|
+
expect(output).toContain("LLM Route Discovery Inputs");
|
|
288
|
+
expect(output).toContain("Static hints available: 0");
|
|
289
|
+
expect(output).toContain("Candidate files to inspect: use the changed files and routing entry-point files above.");
|
|
290
|
+
});
|
|
291
|
+
it("tells LLM route discovery not to turn GraphQL artifacts into REST endpoints", () => {
|
|
253
292
|
const params = baseParams({
|
|
254
293
|
analysisScope: AnalysisScope.CurrentBranchDiff,
|
|
255
294
|
scannedEndpoints: [],
|
|
256
295
|
candidateRouteFiles: ["src/graphql/users.resolver.ts"],
|
|
257
296
|
});
|
|
258
297
|
const output = buildAnalysisOutputText(params);
|
|
259
|
-
expect(output).toContain("
|
|
260
|
-
expect(output).toContain("
|
|
261
|
-
expect(output).toContain("
|
|
298
|
+
expect(output).toContain("Static hints available: 0");
|
|
299
|
+
expect(output).toContain("src/graphql/users.resolver.ts");
|
|
300
|
+
expect(output).toContain("If a file is GraphQL-only, do not invent REST endpoints from it");
|
|
262
301
|
expect(output).not.toContain("Query/Mutation resolvers mapping to endpoints");
|
|
263
302
|
});
|
|
303
|
+
it("omits route discovery section for full-repo scans without route data", () => {
|
|
304
|
+
const params = baseParams({
|
|
305
|
+
analysisScope: AnalysisScope.FullRepo,
|
|
306
|
+
scannedEndpoints: [],
|
|
307
|
+
candidateRouteFiles: [],
|
|
308
|
+
});
|
|
309
|
+
const output = buildAnalysisOutputText(params);
|
|
310
|
+
expect(output).not.toContain("LLM Route Discovery Inputs");
|
|
311
|
+
expect(output).not.toContain("use the changed files and routing entry-point files above");
|
|
312
|
+
});
|
|
313
|
+
it("surfaces router context as source to build an authoritative path table", () => {
|
|
314
|
+
const params = baseParams({
|
|
315
|
+
routerMountContext: ["src/app/router.ts"],
|
|
316
|
+
routerFileContents: [
|
|
317
|
+
{ file: "src/app/router.ts", content: "app.use('/api', router)" },
|
|
318
|
+
],
|
|
319
|
+
candidateRouteFiles: ["src/routes/orders.ts"],
|
|
320
|
+
});
|
|
321
|
+
const output = buildAnalysisOutputText(params);
|
|
322
|
+
expect(output).toContain("Routing entry-point files");
|
|
323
|
+
expect(output).toContain("src/app/router.ts");
|
|
324
|
+
expect(output).toContain("Candidate files to inspect");
|
|
325
|
+
expect(output).toContain("Resolve mount prefixes through the routing entry-point files");
|
|
326
|
+
});
|
|
264
327
|
});
|
|
@@ -123,6 +123,9 @@ Write UI recommendation \`reasoning\` fields in **natural prose** that names ele
|
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
const fmtEndpoint = (m, ep) => ` ${m.method} ${ep.path}${m.authRequired ? " [auth]" : ""} (${(m.interactions ?? []).length} interactions)`;
|
|
126
|
+
// In diff scope, cap the reference endpoint list to prevent context overflow.
|
|
127
|
+
// Changed endpoints are always shown in full; only the "other" list is capped.
|
|
128
|
+
const DIFF_SCOPE_OTHER_ENDPOINT_CAP = 20;
|
|
126
129
|
let endpointLines;
|
|
127
130
|
if (isDiffScope && changedEndpointKeys.size > 0) {
|
|
128
131
|
const changedLines = [];
|
|
@@ -146,7 +149,25 @@ Write UI recommendation \`reasoning\` fields in **natural prose** that names ele
|
|
|
146
149
|
changedLines.push(` ${m.method} ${ep.path} [removed]`);
|
|
147
150
|
}
|
|
148
151
|
}
|
|
149
|
-
|
|
152
|
+
const cappedOther = otherLines.slice(0, DIFF_SCOPE_OTHER_ENDPOINT_CAP);
|
|
153
|
+
const hiddenOtherCount = otherLines.length - cappedOther.length;
|
|
154
|
+
const otherSuffix = hiddenOtherCount > 0
|
|
155
|
+
? `\n ... and ${hiddenOtherCount} more (full endpoint list in state file)`
|
|
156
|
+
: "";
|
|
157
|
+
const otherLabel = hiddenOtherCount > 0
|
|
158
|
+
? `Other endpoints (reference only, ${cappedOther.length} of ${otherLines.length} shown)`
|
|
159
|
+
: "Other endpoints (reference only)";
|
|
160
|
+
endpointLines = `**Likely changed in this PR (from static file→endpoint mapping — verify against diff in Step ${ANALYSIS_STEP_EXTRACT}):**\n${changedLines.join("\n") || " none"}\n\n**${otherLabel}:**\n${cappedOther.join("\n") || " none"}${otherSuffix}`;
|
|
161
|
+
}
|
|
162
|
+
else if (isDiffScope) {
|
|
163
|
+
// Diff scope but no changed endpoints detected — cap to avoid dumping the full catalog.
|
|
164
|
+
const allMethodLines = allEndpoints.flatMap((ep) => (ep.methods ?? []).map((m) => fmtEndpoint(m, ep)));
|
|
165
|
+
const cappedLines = allMethodLines.slice(0, DIFF_SCOPE_OTHER_ENDPOINT_CAP);
|
|
166
|
+
const hiddenCount = allMethodLines.length - cappedLines.length;
|
|
167
|
+
const suffix = hiddenCount > 0
|
|
168
|
+
? `\n ... and ${hiddenCount} more (full endpoint list in state file — trace changed files directly from the diff to find affected endpoints)`
|
|
169
|
+
: "";
|
|
170
|
+
endpointLines = `${cappedLines.join("\n") || " none"}${suffix}`;
|
|
150
171
|
}
|
|
151
172
|
else {
|
|
152
173
|
endpointLines = allEndpoints
|
|
@@ -175,9 +196,22 @@ Write UI recommendation \`reasoning\` fields in **natural prose** that names ele
|
|
|
175
196
|
}
|
|
176
197
|
}
|
|
177
198
|
const { authSchemeSnippet } = getAuthSnippets(authHeaderValue, authTypeValue, workspaceAuthScheme);
|
|
199
|
+
const routeDiscovery = analysis.routeDiscovery;
|
|
200
|
+
const routeDiscoverySection = routeDiscovery
|
|
201
|
+
? `
|
|
202
|
+
## LLM Route Discovery Inputs
|
|
203
|
+
Static endpoint data below is a best-effort hint, not a complete parser for every framework.
|
|
204
|
+
Authoritative endpoint extraction must come from reading the changed source files, router/module context, OpenAPI paths when available, and the diff.
|
|
205
|
+
Candidate files to inspect: ${routeDiscovery.candidateFiles.length > 0 ? routeDiscovery.candidateFiles.join(", ") : "none"}
|
|
206
|
+
Router/module context files: ${routeDiscovery.routerMountContext.length > 0 ? routeDiscovery.routerMountContext.join(", ") : "none"}
|
|
207
|
+
OpenAPI paths available: ${routeDiscovery.openApiPaths.length}
|
|
208
|
+
Static hints available: ${routeDiscovery.staticHints.length}
|
|
209
|
+
${routeDiscovery.diffFilePath ? `Diff file: ${routeDiscovery.diffFilePath}` : ""}
|
|
210
|
+
`.trim()
|
|
211
|
+
: "";
|
|
178
212
|
const sourcePriority = `
|
|
179
213
|
## Source Priority
|
|
180
|
-
When information conflicts, prefer: **Traces** (actual behavior) > **
|
|
214
|
+
When information conflicts, prefer: **Traces** (actual behavior) > **Source code read by the LLM** (implemented behavior) > **OpenAPI spec/docs** (documented behavior) > **Static parser hints** (best-effort, may be incomplete or framework-blind).
|
|
181
215
|
`;
|
|
182
216
|
// Compact fingerprint of tests already covering endpoints in this repo (Skyramp + external).
|
|
183
217
|
// Re-derived fresh each run from test files on disk — no separate persistence needed.
|
|
@@ -219,8 +253,11 @@ Framework: ${analysis.projectClassification.primaryFramework} (${analysis.projec
|
|
|
219
253
|
Project type: ${analysis.projectClassification.projectType}
|
|
220
254
|
Auth: ${authMethod} (header: ${authHeaderValue}${authTypeValue ? `, type: ${authTypeValue}` : ""})
|
|
221
255
|
Base URL: ${analysis.apiEndpoints.baseUrl}
|
|
222
|
-
Candidate
|
|
256
|
+
Candidate endpoint hints from static scan — unverified and non-exhaustive; confirm paths by reading source/router context before use (${analysis.apiEndpoints.totalCount}):
|
|
223
257
|
${endpointLines}${testFingerprint}
|
|
258
|
+
${routeDiscoverySection ? `
|
|
259
|
+
|
|
260
|
+
${routeDiscoverySection}` : ""}
|
|
224
261
|
`.trim();
|
|
225
262
|
// ── Branch diff ──
|
|
226
263
|
let diffSection = "";
|
|
@@ -240,7 +277,7 @@ Affected services: ${diffContext.affectedServices.join(", ") || "N/A"}
|
|
|
240
277
|
|
|
241
278
|
Focus on tests that validate these changes and how they interact with existing resources.
|
|
242
279
|
For removed endpoints: verify they now return 404 or the appropriate deprecation status code.
|
|
243
|
-
|
|
280
|
+
Treat the endpoint lists above as static hints. If source/diff inspection finds a different changed endpoint set, prefer the source-grounded set and use other endpoints only as setup steps.
|
|
244
281
|
`;
|
|
245
282
|
}
|
|
246
283
|
// ── Interactions ──
|
|
@@ -6,7 +6,7 @@ jest.unstable_mockModule("@skyramp/skyramp", () => ({
|
|
|
6
6
|
const { buildRecommendationPrompt, buildExternalCoverageSet, externalDedupKey } = await import("./test-recommendation-prompt.js");
|
|
7
7
|
const { buildExecutionPlan } = await import("./diffExecutionPlan.js");
|
|
8
8
|
const { PATH_PARAM_UUID_GUIDANCE, MAX_TESTS_TO_GENERATE, buildTestQualityCriteria, buildArchitectPreamble, buildContextFetchingGuidance, buildReasoningProtocol, buildFewShotExamples, buildVerificationChecklist, } = await import("./recommendationSections.js");
|
|
9
|
-
import { AnalysisScope } from "../../types/RepositoryAnalysis.js";
|
|
9
|
+
import { AnalysisScope, repositoryAnalysisSchema } from "../../types/RepositoryAnalysis.js";
|
|
10
10
|
// ---------------------------------------------------------------------------
|
|
11
11
|
// Minimal fixtures
|
|
12
12
|
// ---------------------------------------------------------------------------
|
|
@@ -1341,6 +1341,39 @@ describe("buildRecommendationPrompt — data-before-instructions ordering", () =
|
|
|
1341
1341
|
expect(interactionsIdx).toBeLessThan(instructionsIdx);
|
|
1342
1342
|
});
|
|
1343
1343
|
});
|
|
1344
|
+
describe("buildRecommendationPrompt — LLM route discovery contract", () => {
|
|
1345
|
+
it("surfaces route discovery inputs and labels static parser output as hints", () => {
|
|
1346
|
+
const analysis = minimalAnalysis({
|
|
1347
|
+
routeDiscovery: {
|
|
1348
|
+
candidateFiles: ["src/routes/items.ts", "src/app/router.ts"],
|
|
1349
|
+
staticHints: [{ path: "/api/items", methods: ["GET"], sourceFile: "src/routes/items.ts" }],
|
|
1350
|
+
openApiPaths: ["/api/items"],
|
|
1351
|
+
routerMountContext: ["src/app/router.ts"],
|
|
1352
|
+
diffFilePath: "/tmp/skyramp-diff-123.diff",
|
|
1353
|
+
},
|
|
1354
|
+
});
|
|
1355
|
+
const prompt = buildRecommendationPrompt(analysis, AnalysisScope.CurrentBranchDiff, 10);
|
|
1356
|
+
expect(prompt).toContain("LLM Route Discovery Inputs");
|
|
1357
|
+
expect(prompt).toContain("Static endpoint data below is a best-effort hint");
|
|
1358
|
+
expect(prompt).toContain("Candidate files to inspect: src/routes/items.ts, src/app/router.ts");
|
|
1359
|
+
expect(prompt).toContain("Router/module context files: src/app/router.ts");
|
|
1360
|
+
expect(prompt).toContain("Static hints available: 1");
|
|
1361
|
+
expect(prompt).toContain("Static parser hints");
|
|
1362
|
+
});
|
|
1363
|
+
it("repositoryAnalysisSchema preserves routeDiscovery", () => {
|
|
1364
|
+
const analysis = minimalAnalysis({
|
|
1365
|
+
routeDiscovery: {
|
|
1366
|
+
candidateFiles: ["src/routes/items.ts"],
|
|
1367
|
+
staticHints: [{ path: "/api/items", methods: ["GET"], sourceFile: "src/routes/items.ts" }],
|
|
1368
|
+
openApiPaths: ["/api/items"],
|
|
1369
|
+
routerMountContext: ["src/app/router.ts"],
|
|
1370
|
+
diffFilePath: "/tmp/skyramp-diff-123.diff",
|
|
1371
|
+
},
|
|
1372
|
+
});
|
|
1373
|
+
const parsed = repositoryAnalysisSchema.parse(analysis);
|
|
1374
|
+
expect(parsed.routeDiscovery).toEqual(analysis.routeDiscovery);
|
|
1375
|
+
});
|
|
1376
|
+
});
|
|
1344
1377
|
// ---------------------------------------------------------------------------
|
|
1345
1378
|
// Tests — Few-shot examples
|
|
1346
1379
|
// ---------------------------------------------------------------------------
|