test(config): pin that a refused bd config set leaves config.yaml unchanged
setYamlConfigAtPath reads config.yaml, rewrites it through
updateYamlKey, and writes the result back. The AC-1 guard makes
updateYamlKey refuse a document with a line of bufio.MaxScanTokenSize
bytes or more, and setYamlConfigAtPath returns that error before its
os.WriteFile, so the file is never touched. No test covered that order.
TestSetYamlConfigAtPathOversizeLineLeavesFileUntouched writes a
config.yaml with a 65,538-byte comment line, sets no-db, and checks that
the error wraps bufio.ErrTooLong and that the file still holds all
65,563 of its bytes. At 5c9c02ab77 it fails both checks: a nil error,
and the file cut to the 11-byte `no-db: true`. It passes with the AC-1
guard and needs no code change of its own. A variant that writes the
file before returning the error fails the byte check (0 bytes left), and
one that swallows the error fails the error check.
AC: AC-3
Agent-Signature: claude-code-claude-opus-5-5-max on behalf of Julian Knutsen
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
e977179a25
commit
0d3aa63761
1 changed files with 24 additions and 0 deletions
|
|
@ -305,6 +305,30 @@ func TestUpdateYamlKeyRejectsOversizeLine(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// setYamlConfigAtPath is the read, rewrite, write step behind bd config set for
|
||||
// an undotted key. When updateYamlKey refuses a document with an oversize line,
|
||||
// the error has to come back before the write, so config.yaml keeps every byte
|
||||
// it had.
|
||||
func TestSetYamlConfigAtPathOversizeLineLeavesFileUntouched(t *testing.T) {
|
||||
configPath := filepath.Join(t.TempDir(), "config.yaml")
|
||||
before := "no-db: false\n# " + strings.Repeat("x", bufio.MaxScanTokenSize) + "\njson: true\n"
|
||||
if err := os.WriteFile(configPath, []byte(before), 0o600); err != nil {
|
||||
t.Fatalf("failed to write config.yaml: %v", err)
|
||||
}
|
||||
|
||||
if err := setYamlConfigAtPath(configPath, "no-db", "true"); !errors.Is(err, bufio.ErrTooLong) {
|
||||
t.Errorf("setYamlConfigAtPath() error = %v, want %v", err, bufio.ErrTooLong)
|
||||
}
|
||||
|
||||
after, err := os.ReadFile(configPath)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to read config.yaml: %v", err)
|
||||
}
|
||||
if string(after) != before {
|
||||
t.Errorf("config.yaml is %d bytes after the refused set, want the original %d bytes unchanged", len(after), len(before))
|
||||
}
|
||||
}
|
||||
|
||||
func TestFormatYamlValue(t *testing.T) {
|
||||
tests := []struct {
|
||||
value string
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue