Worker para implementación de CRUD de presets con parametrización en Go con TDD.
NOTE: Startup and cleanup are handled by worker-base. This skill defines the WORK PROCEDURE.
Usar para features que implementan:
None - Este worker implementa código Go directamente.
Escribir test que falle primero:
Implementar para hacer pasar:
Tests unitarios:
go test ./internal/preset/... -v -cover
go test ./internal/cli/... -v -cover
Build verificación:
go build ./...
go build -o mapj.exe ./cmd/mapj
Verificación manual:
Todos los outputs deben usar el sistema de envelopes existente:
// Éxito
env := output.NewEnvelope(cmd.CommandPath(), result)
fmt.Println(formatter.Format(env))
// Error
env := output.NewErrorEnvelope(cmd.CommandPath(), "ERROR_CODE", message, retryable)
fmt.Println(formatter.Format(env))
// Error con hint
env := output.NewErrorEnvelopeWithHint(cmd.CommandPath(), "ERROR_CODE", message, hint, retryable)
fmt.Println(formatter.Format(env))
Para features de escaping y validación:
Implementar detección de patrones:
; DROP, ; DELETE, etc.OR 1=1, OR '1'='1'UNION SELECT-- comment injectionImplementar escaping:
' → '' para strings'a', 'b', 'c' para listasTests exhaustivos de seguridad:
{
"salientSummary": "Implemented PresetStore with atomic writes, QueryPreset and ParamDef structures, and Load/Save operations. All 15 storage tests pass. File permissions set to 0600, atomic write via temp file + rename.",
"whatWasImplemented": "Preset Storage Infrastructure: (1) internal/preset/store.go with PresetStore, QueryPreset, ParamDef, PresetFile structures, (2) Load() handles missing file and corrupted JSON gracefully, (3) Save() creates directory, uses atomic write, sets 0600 permissions, (4) JSON formatted with indentation for readability, (5) Active preset tracking persists between sessions.",
"whatWasLeftUndone": "",
"verification": {
"commandsRun": [
{
"command": "go test ./internal/preset/... -v -run TestPresetStore",
"exitCode": 0,
"observation": "All 15 storage tests pass including atomic write, permissions, error handling"
},
{
"command": "go test ./internal/preset/... -cover",
"exitCode": 0,
"observation": "Coverage: 92.3%"
},
{
"command": "go build -o mapj.exe ./cmd/mapj",
"exitCode": 0,
"observation": "Build successful, no errors"
}
],
"interactiveChecks": [
{
"action": "Manual test: Create preset and verify file",
"observed": "File created at ~/.config/mapj/presets.json with correct JSON structure and 0600 permissions"
}
]
},
"tests": {
"added": [
{
"file": "internal/preset/store_test.go",
"cases": [
{"name": "TestNewPresetStore", "verifies": "Store creation with correct path"},
{"name": "TestLoadMissingFile", "verifies": "Graceful handling of missing file"},
{"name": "TestLoadCorruptedJSON", "verifies": "Error on corrupted JSON"},
{"name": "TestSaveCreatesDirectory", "verifies": "Directory creation on first save"},
{"name": "TestSaveAtomicWrite", "verifies": "Temp file + rename pattern"},
{"name": "TestSavePermissions", "verifies": "0600 file permissions"},
{"name": "TestQueryPresetStructure", "verifies": "All fields present"},
{"name": "TestParamDefStructure", "verifies": "All fields present"},
{"name": "TestActivePresetPersistence", "verifies": "Active preset survives sessions"}
]
}
]
},
"discoveredIssues": []
}