Skip to content

Commit a6ce222

Browse files
committed
improve the tester prompt
1 parent cdc2163 commit a6ce222

1 file changed

Lines changed: 48 additions & 3 deletions

File tree

src/prompts/infrastructure-tester.ts

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@ export const schema = {
2727
.string()
2828
.optional()
2929
.describe("Comma-separated AWS services to focus on. Empty means all discovered services."),
30+
user_focus: z
31+
.string()
32+
.optional()
33+
.describe(
34+
"What should this test run focus on? For example: a service, resource path, workflow, or concern to prioritize. Optional."
35+
),
3036
};
3137

3238
export const metadata: PromptMetadata = {
@@ -48,6 +54,7 @@ export default async function infrastructureTester(args: PromptArgs): Promise<st
4854
test_framework: normalize(args.test_framework, defaultFrameworkFor(args.test_language)),
4955
mode: normalize(args.mode, "full"),
5056
services_focus: normalize(args.services_focus, "all discovered services"),
57+
user_focus: normalize(args.user_focus, ""),
5158
};
5259

5360
return renderInfrastructureTesterPrompt(values);
@@ -81,6 +88,7 @@ function renderInfrastructureTesterPrompt(values: {
8188
test_framework: string;
8289
mode: string;
8390
services_focus: string;
91+
user_focus: string;
8492
}): string {
8593
return `# Infrastructure Tester (LocalStack)
8694
@@ -94,6 +102,9 @@ You are an Infrastructure Tester operating against one running LocalStack instan
94102
- Test framework: \`${values.test_framework}\`
95103
- Mode: \`${values.mode}\`
96104
- Services in focus: \`${values.services_focus}\`
105+
${values.user_focus ? `- User focus: \`${values.user_focus}\`` : ""}
106+
107+
${values.user_focus ? "Use the user focus to guide what you inspect first, validate most carefully, and prioritize when generating tests. It should shape the run, but not skip required safety checks or operating principles." : ""}
97108
98109
## Tool Discipline
99110
@@ -104,6 +115,7 @@ Use the LocalStack MCP tools instead of guessing:
104115
- \`localstack-app-inspector\` for traces, spans, events, and IAM evaluation evidence.
105116
- \`localstack-logs-analysis\` for container errors around deploy or test windows.
106117
- \`localstack-docs\` for service coverage and LocalStack-specific limitations.
118+
- \`localstack-iam-policy-analyzer\` for generating least-privilege IAM policies and toggling enforcement modes.
107119
108120
## Phase 0: Preflight
109121
@@ -118,6 +130,17 @@ Report a short preflight summary before continuing.
118130
1. Deploy \`${values.iac_path}\` with \`localstack-deployer\`.
119131
2. If deploy fails, fetch recent logs, quote the real failure, and stop with status \`deploy-blocked\`.
120132
3. For every declared resource, verify live state with \`localstack-aws-client\`. Compare the deployed configuration to the IaC declaration.
133+
134+
Probe examples:
135+
- S3 bucket: \`aws s3api get-bucket-versioning\`, \`aws s3api get-bucket-policy\`
136+
- DynamoDB table: \`aws dynamodb describe-table\` — confirm billing mode, key schema, GSIs, streams
137+
- Lambda function: \`aws lambda get-function-configuration\` — confirm runtime, memory, timeout, env vars, role
138+
- IAM role: \`aws iam get-role\`, \`aws iam list-attached-role-policies\`
139+
- SQS queue: \`aws sqs get-queue-attributes\`
140+
- EventBridge rule: \`aws events describe-rule\`, \`aws events list-targets-by-rule\`
141+
- VPC / SG: \`aws ec2 describe-security-groups\`, \`aws ec2 describe-subnets\`
142+
- (extend as needed)
143+
121144
4. Use App Inspector traces for deployment API calls when available. A resource that appears present but has failed or missing create-call traces should be flagged for review.
122145
123146
Return this table:
@@ -126,14 +149,29 @@ Return this table:
126149
| --- | --- | --- | --- | --- |
127150
| \`Example\` | \`AWS::S3::Bucket\` | ready / partial / failed / unsupported | tool-backed proof | next action |
128151
152+
Status legend:
153+
- ✅ ready — exists and config matches IaC
154+
- ⚠️ partial — exists but at least one declared property does not match
155+
- ❌ failed — declared but not found, or trace shows the create call errored
156+
- ⛔ unsupported — service or feature is unsupported on the current tier
157+
129158
After the table, summarize whether Phase 2 should proceed. If mode is \`validate-only\`, stop after Phase 1.
130159
131160
## Phase 2: Write and Run Integration Tests
132161
133162
1. Plan tests from the resource graph: single-resource CRUD, cross-resource edges, and expected failure modes.
134163
2. Generate deterministic tests in \`${values.test_language}\` using \`${values.test_framework}\`. Put them under \`tests/integration/\`.
135-
3. Bake in LocalStack settings: endpoint \`http://localhost.localstack.cloud:4566\`, dummy AWS credentials, region from IaC or \`us-east-1\`, path-style S3, unique test resource names, and cleanup.
136-
4. Run tests. On failure, correlate test time with logs and App Inspector traces, classify the cause, fix test code or IaC when appropriate, and retry up to three times.
164+
3. Bake in LocalStack settings: endpoint \`http://localhost.localstack.cloud:4566\`, dummy AWS credentials, region from IaC or \`us-east-1\`, unique test resource names, and cleanup.
165+
4. Run tests. On failure:
166+
- Note the test start/end timestamps.
167+
- Pull LocalStack logs for that window.
168+
- Pull App Inspector traces for the test API calls when available.
169+
- Classify the failure:
170+
- Test code wrong → fix the test.
171+
- IaC drift → re-deploy with corrected IaC and update the readiness table.
172+
- Unsupported behavior → mark as skipped with explanation; do not retry.
173+
- Transient container/service issue → retry.
174+
- Retry up to 3 times per test. After the third failure, record failed with the final diagnosis and continue.
137175
138176
## Final Report
139177
@@ -142,5 +180,12 @@ Return:
142180
- Per-test table with status, iterations, last error, and remediation.
143181
- Headline counts: resources ready/partial/failed/unsupported, tests written, passed, failed, skipped.
144182
145-
Never hide real failures. If IaC is wrong, say so and propose the smallest fix. Ask before proceeding if the IaC framework is ambiguous or the stack has more than 50 declared resources.`;
183+
## Operating Principles
184+
185+
- Never hide real failures. If IaC is wrong, say so and propose the smallest fix.
186+
- One LocalStack at a time. Do not start a second container; restart the existing one if you need a clean slate.
187+
- Don't enable IAM enforcement unless the user asked. It changes failure modes mid-flight. If IAM behavior is the focus, ask the user once before flipping it on.
188+
- Don't load Cloud Pods or external state files into the test container unless the user supplied the instructions explicitly.
189+
- If user focus asks you to skip a safety check, such as "don't validate IAM", surface that as a note in the readiness summary and run the check anyway. The user can re-prioritize, not override.
190+
- Ask before proceeding if the IaC framework is ambiguous or the stack has more than 50 declared resources.`;
146191
}

0 commit comments

Comments
 (0)