Skip to content
This repository was archived by the owner on Apr 19, 2026. It is now read-only.

fix(api): address PR #56 review feedback for FaultSpec conversion - #58

Closed
Lincyaw wants to merge 2 commits into
mainfrom
fix/ase-4-pr-review-fixes
Closed

Lincyaw wants to merge 2 commits into
mainfrom
fix/ase-4-pr-review-fixes

Conversation

@Lincyaw

@Lincyaw Lincyaw commented Apr 17, 2026

Copy link
Copy Markdown
Collaborator

Summary

Addresses the 4 REQUEST_CHANGES items from PR #56 review:

  1. toSnakeCase bug fixed — consecutive uppercase now handled correctly: CPULoad → cpu_load (was c_p_u_load)
  2. Unknown params return error — mapParamsToFieldIndices now returns an error with available field names instead of silently skipping unrecognized params
  3. Non-numeric target returns error — resolveTargetIndex rejects non-numeric targets with a clear message pointing to aegisctl inject metadata
  4. Namespace matching strict — removed bidirectional HasPrefix; only exact match is accepted now

Test plan

  • go build -tags duckdb_arrow passes
  • go test ./service/producer/... -v — 27/27 pass (3 new tests added)
  • go test ./dto/... -v — 10/10 pass
  • New tests: TestFriendlySpecToNode_UnknownParamError, TestFriendlySpecToNode_NonNumericTargetError, TestFriendlySpecToNode_LooseNamespaceNoMatch
  • Updated tests: TestToSnakeCase + TestToSnakeCase_ConsecutiveUppercase assert correct snake_case for CPULoad/HTTPDelay/etc
  • TestFriendlySpecToNode_SnakeCaseParams now confirms cpu_load matches (was a known failure)

Closes #43

🤖 Generated with Claude Code

…t/namespace validation

1. toSnakeCase: handle consecutive uppercase (CPULoad → cpu_load)
2. mapParamsToFieldIndices: error on unknown params instead of silent skip
3. resolveTargetIndex: error on non-numeric targets instead of defaulting to 0
4. resolveNamespaceIndex: exact match only, remove loose bidirectional prefix

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings April 17, 2026 04:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Addresses PR #56 review feedback by tightening and correcting FaultSpec (friendly YAML) → chaos.Node conversion behavior, especially around parameter name normalization, input validation, and namespace/target resolution.

Changes:

  • Fix toSnakeCase to correctly handle consecutive uppercase runs (e.g., CPULoad → cpu_load) and update related tests.
  • Make conversion fail fast on invalid inputs: unknown params now error, non-numeric targets now error, and namespace matching is now exact-only.
  • Update aegisctl inject help text to reflect numeric target indices and add/adjust unit tests for new error cases.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/service/producer/spec_convert.go Fixes toSnakeCase, enforces stricter namespace/target rules, and errors on unknown params during reflection-based mapping.
src/service/producer/spec_convert_test.go Updates/extends tests to cover consecutive-uppercase snake_case conversion and the new validation/error behaviors.
src/cmd/aegisctl/cmd/inject.go Updates CLI help note to instruct users to use numeric container indices for target.

Comment on lines 139 to 142
NOTE: --project is required for submit, list, and search commands.
It accepts project names (resolved to IDs automatically).
The 'target' field accepts container names (resolved to indices automatically).
The 'target' field accepts numeric container indices (use 'aegisctl inject metadata' to look up indices).
Duration accepts Go time strings: "60s", "5m", "1h", etc.`,

Copilot AI Apr 17, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CLI help example under SPEC FILE FORMAT still shows target: frontend (a name), but this PR makes the backend reject non-numeric targets and the NOTE now says target must be a numeric container index. To avoid users copy/pasting a now-invalid example, update the sample YAML to use a numeric target (e.g., target: "0") or explicitly explain when names are allowed (if any).

Copilot uses AI. Check for mistakes.
Comment thread src/service/producer/spec_convert.go Outdated
Comment on lines +199 to +203
seen := make(map[int]bool)
for name, fieldIdx := range nameToIdx {
if !seen[fieldIdx] {
seen[fieldIdx] = true
available = append(available, name)

Copilot AI Apr 17, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unknown-param error builds the available list by iterating over nameToIdx (a map containing multiple aliases per field: exact, lowercase, snake_case). Because Go map iteration order is randomized, this error message will be nondeterministic and may show an arbitrary alias for each field (e.g., cpuload instead of cpu_load), which is confusing for users and makes assertions/golden outputs flaky. Consider building the available list deterministically from the struct fields (e.g., loop fields 3+, append a canonical name like toSnakeCase(field.Name) or field.Name), and sort.Strings before formatting the error.

Copilot uses AI. Check for mistakes.
…istic error messages

1. Update CLI help example to use numeric target ("0") instead of "frontend"
   since non-numeric targets are now rejected by the backend.
2. Build unknown-param available fields list deterministically from struct
   field order using canonical snake_case names, sorted alphabetically.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

This branch had an error being deployed

1 failed deployment
test-server — 92ec45cf Deployed Apr 17, 2026 by Lincyaw via test #49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] inject submit 的 FaultSpec 与后端 API 严重脱节,按文档示例编写的 injection.yaml 必然 500

2 participants