-
Notifications
You must be signed in to change notification settings - Fork 1
fix(jtk): auto create has two bugs — doesn't strip UUIDs and misparses response #104
Description
Bug 1: Export-then-create fails because UUIDs are not stripped
The auto create help text says:
Fields like 'id' and 'ruleKey' from the exported JSON are ignored — the new rule gets its own identifiers.
But this is not true. The exported JSON is sent as-is to the API, including the uuid field. The API rejects it with:
Can't create a rule with a UUID that already exists.
Steps to Reproduce
jtk auto export <uuid> > /tmp/rule.json
# Edit name only
jtk auto create --file /tmp/rule.jsonExpected: Rule created with new UUID
Actual: failed to create automation rule: bad request
Root Cause
runCreate() in internal/cmd/automation/create.go reads the file and sends it directly to the API without stripping identifier fields. The uuid field in the exported JSON causes the conflict.
Fix
Before sending to the API, strip uuid, id, ruleKey, created, and updated from the rule object. These are server-assigned fields.
Bug 2: Success message shows empty UUID
After a successful create (with manually stripped UUIDs), the output is:
✓ Created automation rule (UUID: )
The identifier is blank.
Root Cause
The API returns {"ruleUuid": "..."} but the response struct (line 70-77) only maps:
json:"id"json:"ruleKey"json:"uuid"json:"name"
It should also map ruleUuid:
var created struct {
ID json.Number `json:"id"`
RuleKey string `json:"ruleKey"`
UUID string `json:"uuid"`
RuleUUID string `json:"ruleUuid"` // ← missing
Name string `json:"name"`
}And the identifier resolution should check RuleUUID too:
identifier := created.UUID
if identifier == "" {
identifier = created.RuleUUID
}
// ...Found During
Integration testing of jtk auto create.