Remove unnecessary output restrictions and simplify report tests
This commit is contained in:
@@ -638,3 +638,64 @@ func TestSubprocessInteractionWriteFailureIsVisibleAndNonfatal(t *testing.T) {
|
||||
t.Fatalf("debug failure classified as model incident: %+v", document)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSubprocessInPlaceTranscript(t *testing.T) {
|
||||
for _, invalid := range []bool{false, true} {
|
||||
t.Run(fmt.Sprint(invalid), func(t *testing.T) {
|
||||
f := newProcessFixture(t, "success", "[grammar]")
|
||||
f.output = f.transcript
|
||||
if invalid {
|
||||
if err := os.WriteFile(f.transcript, []byte("invalid"), 0600); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
before, err := os.ReadFile(f.transcript)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
code, stdout, stderr := f.run(t, true)
|
||||
after, err := os.ReadFile(f.transcript)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if invalid {
|
||||
if code != 1 || !bytes.Equal(before, after) {
|
||||
t.Fatalf("failed processing changed input: code=%d %s", code, stderr)
|
||||
}
|
||||
} else if code != 0 || stdout != "" || !bytes.Contains(after, []byte("Hello world")) {
|
||||
t.Fatalf("in-place publication failed: code=%d %s %s", code, stderr, after)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSubprocessProfileSources(t *testing.T) {
|
||||
f := newProcessFixture(t, "success", "[]")
|
||||
// PromptKit uses profile IDs, not filename stems. A report-named profile is
|
||||
// still an input and must not be overwritten during report initialization.
|
||||
loaded := filepath.Join(f.dir, "profiles", "errors.yml")
|
||||
if err := os.Rename(filepath.Join(f.dir, "profiles", "proposal.yaml"), loaded); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
before, err := os.ReadFile(loaded)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
f.output = filepath.Join(f.dir, "profiles", "proposal.yml")
|
||||
code, _, stderr := f.run(t, true, "--reporting=false")
|
||||
if code != 0 {
|
||||
t.Fatalf("unused alternate rejected: %d %s", code, stderr)
|
||||
}
|
||||
// Remove the transcript from the profile directory before the next load.
|
||||
if err := os.Remove(f.output); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
code, _, stderr = f.run(t, true)
|
||||
after, err := os.ReadFile(loaded)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if code != 2 || !bytes.Equal(before, after) || f.provider.callCount() != 0 {
|
||||
t.Fatalf("loaded profile not protected: %d %s", code, stderr)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user