Never list index.mf at the top of the tree in gen and freshen (closes #233)
check / check (push) Canceled after 0s
check / check (push) Canceled after 0s
fetch saves the manifest as index.mf at the top of the tree and refuses a manifest that lists a file there. gen given --output, and freshen with its manifest outside the base directory, listed such a file, so they wrote manifests fetch would not take. gen now leaves out index.mf in each directory it is given, or beside each file it is given, the same way it leaves out the file it writes. freshen leaves out index.mf at the top of the base directory. index.mf in a subdirectory is still listed. The README says so for both commands. Model: opus-5-5
This commit is contained in:
@@ -1420,6 +1420,66 @@ func TestGenerateLeavesLeftoverTempFileOutOfListing(t *testing.T) {
|
||||
assert.Equal(t, []string{testFileTxt}, manifestPaths(t, fs, output))
|
||||
}
|
||||
|
||||
// TestGenerateLeavesTopIndexMFOutOfListing runs gen with --output outside
|
||||
// the paths it is given: index.mf at the top of each directory given, and
|
||||
// a file given by that name, are not listed, since fetch saves the manifest
|
||||
// as index.mf at the top of the tree, while sub/index.mf is listed. The
|
||||
// files are recognized by file identity, which needs the real filesystem.
|
||||
func TestGenerateLeavesTopIndexMFOutOfListing(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
// Paths are relative to a temp dir holding tree, which holds file.txt,
|
||||
// index.mf and sub/index.mf, and second, which holds second.txt and
|
||||
// index.mf.
|
||||
for name, tc := range map[string]struct {
|
||||
paths []string
|
||||
listed []string
|
||||
}{
|
||||
"directory": {
|
||||
[]string{"tree"},
|
||||
[]string{testFileTxt, testSubdirManifest},
|
||||
},
|
||||
"two directories": {
|
||||
[]string{"tree", "second"},
|
||||
[]string{testFileTxt, testSubdirManifest, "second.txt"},
|
||||
},
|
||||
"files": {
|
||||
[]string{"tree/" + testFileTxt, "tree/" + defaultManifestName},
|
||||
[]string{testFileTxt},
|
||||
},
|
||||
} {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
root := t.TempDir()
|
||||
tree := filepath.Join(root, "tree")
|
||||
second := filepath.Join(root, "second")
|
||||
|
||||
fs := afero.NewOsFs()
|
||||
require.NoError(t, fs.MkdirAll(filepath.Join(tree, testSubdir), 0o750))
|
||||
require.NoError(t, fs.MkdirAll(second, 0o750))
|
||||
writeTestFile(t, fs, filepath.Join(tree, testFileTxt), "hello")
|
||||
writeTestFile(t, fs, filepath.Join(tree, defaultManifestName), "an ordinary file")
|
||||
writeTestFile(t, fs, filepath.Join(tree, testSubdirManifest), "an ordinary file")
|
||||
writeTestFile(t, fs, filepath.Join(second, "second.txt"), "second")
|
||||
writeTestFile(t, fs, filepath.Join(second, defaultManifestName), "an ordinary file")
|
||||
|
||||
paths := make([]string, 0, len(tc.paths))
|
||||
for _, path := range tc.paths {
|
||||
paths = append(paths, filepath.Join(root, path))
|
||||
}
|
||||
|
||||
output := filepath.Join(root, "other.mf")
|
||||
opts := testOpts(slices.Concat(
|
||||
[]string{testApp, cmdGenerate, "-q", "-o", output}, paths,
|
||||
), fs)
|
||||
require.Equal(t, 0, runCLI(opts), "stderr: %s", testStderr(t, opts))
|
||||
|
||||
assert.ElementsMatch(t, tc.listed, manifestPaths(t, fs, output))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// writeTestTree writes file.txt and sub/nested.txt under dir.
|
||||
func writeTestTree(t *testing.T, fs afero.Fs, dir string) {
|
||||
t.Helper()
|
||||
|
||||
Reference in New Issue
Block a user