Close out the repository audit
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
//go:build unix
|
||||
|
||||
package promptdebug
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"sync"
|
||||
"testing"
|
||||
@@ -12,6 +13,7 @@ import (
|
||||
|
||||
"gitea.maximumdirect.net/eric/weatherreporter/internal/promptexec"
|
||||
"gitea.maximumdirect.net/eric/weatherreporter/internal/report"
|
||||
"gitea.maximumdirect.net/eric/weatherreporter/internal/testutil"
|
||||
)
|
||||
|
||||
func TestPromptDebugWriterWritesIsolatedArtifacts(t *testing.T) {
|
||||
@@ -58,12 +60,10 @@ func TestPromptDebugWriterWritesIsolatedArtifacts(t *testing.T) {
|
||||
t.Fatalf("debug artifact contains credentials:\n%s", data)
|
||||
}
|
||||
}
|
||||
if runtime.GOOS != "windows" {
|
||||
assertPromptDebugMode(t, root, debugDirectoryMode)
|
||||
assertPromptDebugMode(t, preparationDir, debugDirectoryMode)
|
||||
assertPromptDebugMode(t, filepath.Join(preparationDir, "preparation.json"), debugFileMode)
|
||||
assertPromptDebugMode(t, filepath.Join(executionDir, "execution.json"), debugFileMode)
|
||||
}
|
||||
assertPromptDebugMode(t, root, debugDirectoryMode)
|
||||
assertPromptDebugMode(t, preparationDir, debugDirectoryMode)
|
||||
assertPromptDebugMode(t, filepath.Join(preparationDir, "preparation.json"), debugFileMode)
|
||||
assertPromptDebugMode(t, filepath.Join(executionDir, "execution.json"), debugFileMode)
|
||||
}
|
||||
|
||||
func TestPromptDebugWriterProjectsProviderConfigurationSafely(t *testing.T) {
|
||||
@@ -222,21 +222,16 @@ func TestPromptDebugWriterCreatesSharedMissingAncestorsConcurrently(t *testing.T
|
||||
if len(directories) != writerCount {
|
||||
t.Fatalf("debug directories = %#v", directories)
|
||||
}
|
||||
if runtime.GOOS != "windows" {
|
||||
assertPromptDebugMode(t, root, debugDirectoryMode)
|
||||
assertPromptDebugMode(t, filepath.Join(root, "daily"), debugDirectoryMode)
|
||||
assertPromptDebugMode(t, filepath.Join(root, "daily", "2026-05-29"), debugDirectoryMode)
|
||||
for directory := range directories {
|
||||
assertPromptDebugMode(t, directory, debugDirectoryMode)
|
||||
assertPromptDebugMode(t, filepath.Join(directory, "preparation.json"), debugFileMode)
|
||||
}
|
||||
assertPromptDebugMode(t, root, debugDirectoryMode)
|
||||
assertPromptDebugMode(t, filepath.Join(root, "daily"), debugDirectoryMode)
|
||||
assertPromptDebugMode(t, filepath.Join(root, "daily", "2026-05-29"), debugDirectoryMode)
|
||||
for directory := range directories {
|
||||
assertPromptDebugMode(t, directory, debugDirectoryMode)
|
||||
assertPromptDebugMode(t, filepath.Join(directory, "preparation.json"), debugFileMode)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPromptDebugWriterKeepsWritesAnchoredToOpenedRoot(t *testing.T) {
|
||||
if runtime.GOOS == "windows" {
|
||||
t.Skip("directory replacement behavior is covered on Unix hosts")
|
||||
}
|
||||
parent := t.TempDir()
|
||||
root := filepath.Join(parent, "debug")
|
||||
writer, err := NewPromptDebugWriter(root)
|
||||
@@ -253,7 +248,7 @@ func TestPromptDebugWriterKeepsWritesAnchoredToOpenedRoot(t *testing.T) {
|
||||
if err := os.Rename(root, anchoredRoot); err != nil {
|
||||
t.Fatalf("replace opened root: %v", err)
|
||||
}
|
||||
requireSymlink(t, outside, root)
|
||||
testutil.RequireSymlink(t, outside, root)
|
||||
|
||||
ref := promptDebugRef()
|
||||
ref.RunID = "run-anchored"
|
||||
@@ -299,16 +294,14 @@ func TestPromptDebugWriterRejectsUnsafeRootsAndReferences(t *testing.T) {
|
||||
if _, err := NewPromptDebugWriter(nonDirectory); err == nil {
|
||||
t.Fatal("NewPromptDebugWriter(file) error = nil")
|
||||
}
|
||||
if runtime.GOOS != "windows" {
|
||||
target := filepath.Join(root, "target")
|
||||
link := filepath.Join(root, "root-link")
|
||||
if err := os.Mkdir(target, debugDirectoryMode); err != nil {
|
||||
t.Fatalf("create root symlink target: %v", err)
|
||||
}
|
||||
requireSymlink(t, target, link)
|
||||
if _, err := NewPromptDebugWriter(link); err == nil {
|
||||
t.Fatal("NewPromptDebugWriter(symlink) error = nil")
|
||||
}
|
||||
target := filepath.Join(root, "target")
|
||||
link := filepath.Join(root, "root-link")
|
||||
if err := os.Mkdir(target, debugDirectoryMode); err != nil {
|
||||
t.Fatalf("create root symlink target: %v", err)
|
||||
}
|
||||
testutil.RequireSymlink(t, target, link)
|
||||
if _, err := NewPromptDebugWriter(link); err == nil {
|
||||
t.Fatal("NewPromptDebugWriter(symlink) error = nil")
|
||||
}
|
||||
|
||||
writer, err := NewPromptDebugWriter(filepath.Join(root, "debug"))
|
||||
@@ -325,22 +318,13 @@ func TestPromptDebugWriterRejectsUnsafeRootsAndReferences(t *testing.T) {
|
||||
t.Fatalf("WritePreparation(%#v) error = nil", ref)
|
||||
}
|
||||
}
|
||||
if runtime.GOOS != "windows" {
|
||||
outside := filepath.Join(root, "outside")
|
||||
if err := os.Mkdir(outside, debugDirectoryMode); err != nil {
|
||||
t.Fatalf("create symlink component target: %v", err)
|
||||
}
|
||||
requireSymlink(t, outside, filepath.Join(root, "debug", "daily"))
|
||||
if _, err := writer.WritePreparation(promptDebugRef(), promptDebugPreparationFixture(), nil); err == nil {
|
||||
t.Fatal("WritePreparation(symlink component) error = nil")
|
||||
}
|
||||
outside := filepath.Join(root, "outside")
|
||||
if err := os.Mkdir(outside, debugDirectoryMode); err != nil {
|
||||
t.Fatalf("create symlink component target: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func requireSymlink(t *testing.T, target string, link string) {
|
||||
t.Helper()
|
||||
if err := os.Symlink(target, link); err != nil {
|
||||
t.Skipf("symlink support is unavailable: %v", err)
|
||||
testutil.RequireSymlink(t, outside, filepath.Join(root, "debug", "daily"))
|
||||
if _, err := writer.WritePreparation(promptDebugRef(), promptDebugPreparationFixture(), nil); err == nil {
|
||||
t.Fatal("WritePreparation(symlink component) error = nil")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user