Stream verified prepared inputs into publication archives
This commit is contained in:
@@ -10,7 +10,7 @@ documentation, focused diagnostic reproductions, and repository checks.
|
|||||||
An integration-focused follow-up reviewed the same implementation at
|
An integration-focused follow-up reviewed the same implementation at
|
||||||
`bccf03a99f45c2b9b342412b85f70e356663df61`, tracing each stage into existing
|
`bccf03a99f45c2b9b342412b85f70e356663df61`, tracing each stage into existing
|
||||||
command, preparation, publication, restore, and inspection workflows. Items
|
command, preparation, publication, restore, and inspection workflows. Items
|
||||||
5–6 are additional findings from that pass; items 1–4 remain outstanding.
|
5–6 were additional findings from that pass; items 1–4 were outstanding then.
|
||||||
|
|
||||||
An algorithm-focused pass reviewed all twelve stages at
|
An algorithm-focused pass reviewed all twelve stages at
|
||||||
`583c5bdf1bc8f0af8ec2e257bcb03ecccbf283b1`. Items 7–10 are refactoring
|
`583c5bdf1bc8f0af8ec2e257bcb03ecccbf283b1`. Items 7–10 are refactoring
|
||||||
@@ -18,9 +18,8 @@ opportunities for consideration. Complexity follows the code and the selected
|
|||||||
ConfigKit v1.2.1 implementation; no operational timings or benchmarks were
|
ConfigKit v1.2.1 implementation; no operational timings or benchmarks were
|
||||||
collected. The pass preserves algorithms expressly chosen by the plan.
|
collected. The pass preserves algorithms expressly chosen by the plan.
|
||||||
|
|
||||||
The native configuration architecture is substantially implemented. The items
|
All ten items below are now complete. The original findings are retained with
|
||||||
below record the six required corrections and four additional algorithmic
|
completion annotations; final verification is recorded at the end of this file.
|
||||||
opportunities. This document implements none of their fixes.
|
|
||||||
|
|
||||||
## 1. P2: Distinguish effective resource origins from superseded history
|
## 1. P2: Distinguish effective resource origins from superseded history
|
||||||
|
|
||||||
@@ -332,6 +331,10 @@ temporary-file cleanup. Confirm that unrelated historical keys are not enumerate
|
|||||||
|
|
||||||
## 10. P3: Stream prepared-input archival copies
|
## 10. P3: Stream prepared-input archival copies
|
||||||
|
|
||||||
|
Status: Complete. Verified descriptors stream through the existing atomic-reader
|
||||||
|
copy helper, with unchanged-destination reuse. Archive bytes, checksums, modes,
|
||||||
|
and tamper rejection are covered; full ordinary and race suites pass.
|
||||||
|
|
||||||
Stage: 7.
|
Stage: 7.
|
||||||
|
|
||||||
Location: `internal/stage/publish_sources.go:29–64`,
|
Location: `internal/stage/publish_sources.go:29–64`,
|
||||||
@@ -356,7 +359,7 @@ validation, failure handling, and immutable publication behavior. Existing
|
|||||||
reader-copy and prepared-session publication tests provide suitable behavioral
|
reader-copy and prepared-session publication tests provide suitable behavioral
|
||||||
coverage; allocation or wall-clock thresholds are unnecessary.
|
coverage; allocation or wall-clock thresholds are unnecessary.
|
||||||
|
|
||||||
## Stage-by-stage disposition
|
## Stage-by-stage disposition at the initial reviews
|
||||||
|
|
||||||
| Stage | Review result |
|
| Stage | Review result |
|
||||||
| --- | --- |
|
| --- | --- |
|
||||||
@@ -436,3 +439,21 @@ and under `-race`. Focused configuration, file-reader copy, S3 opened-object
|
|||||||
metadata, native inspection, and prepared-session publication checks passed on
|
metadata, native inspection, and prepared-session publication checks passed on
|
||||||
Go 1.27.4. No performance data, timing assertions, benchmark gates, or application
|
Go 1.27.4. No performance data, timing assertions, benchmark gates, or application
|
||||||
changes were introduced.
|
changes were introduced.
|
||||||
|
|
||||||
|
## Completed remediation validation
|
||||||
|
|
||||||
|
Each issue was addressed in order and committed with its completion marker.
|
||||||
|
Using Go 1.27.4 on the completed implementation:
|
||||||
|
|
||||||
|
- `go test ./...` passed.
|
||||||
|
- `go test -race ./...` passed, including the corrected restore contention test.
|
||||||
|
- `go vet ./...`, `go build ./...`, and `go mod tidy -diff` passed.
|
||||||
|
- Focused regressions cover effective provenance, field-level publish history,
|
||||||
|
local/imported initialization, standalone remote input, remote authoring after
|
||||||
|
publication, enumeration-free loading, and verified streaming archives.
|
||||||
|
- Documentation checks and `git diff --check` passed.
|
||||||
|
|
||||||
|
Remote session authoring updates affect future command inputs. Committed
|
||||||
|
publication objects remain immutable and restore continues to validate its
|
||||||
|
pointer-selected remote state. Inspection caches are scoped to one operation;
|
||||||
|
ConfigKit remains the authority for configuration and provenance.
|
||||||
|
|||||||
49
internal/stage/publish_prepared_test.go
Normal file
49
internal/stage/publish_prepared_test.go
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
package stage
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestPublishPreparedInputsRetainVerifiedBytesAndRejectTampering(t *testing.T) {
|
||||||
|
env, m, _ := prepareResumeLocalFixture(t)
|
||||||
|
paths := sessionPathsForEnv(env, m.SessionID)
|
||||||
|
runRoot := filepath.Join(paths.Root, "runs", "20260519T010203Z-a1b2c3d4")
|
||||||
|
files, err := collectPublishPreparedInputs(env.ArtifactStore, paths, runRoot, m.Inputs)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if len(files) != 3 {
|
||||||
|
t.Fatalf("prepared archive files = %d", len(files))
|
||||||
|
}
|
||||||
|
for _, file := range files {
|
||||||
|
path := filepath.Join(runRoot, filepath.FromSlash(file.RelativePath))
|
||||||
|
checksum, err := env.ArtifactStore.Checksum(path)
|
||||||
|
if err != nil || checksum != file.Checksum {
|
||||||
|
t.Fatalf("archive checksum = %q, %v", checksum, err)
|
||||||
|
}
|
||||||
|
info, err := os.Stat(path)
|
||||||
|
if err != nil || info.Mode().Perm() != 0o664 {
|
||||||
|
t.Fatalf("archive mode: %v, %v", info, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
archivedParty := filepath.Join(runRoot, "prepare", "inputs", "party.yml")
|
||||||
|
before, err := os.ReadFile(archivedParty)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if _, err := collectPublishPreparedInputs(env.ArtifactStore, paths, runRoot, m.Inputs); err != nil {
|
||||||
|
t.Fatalf("reuse archive: %v", err)
|
||||||
|
}
|
||||||
|
if err := os.WriteFile(filepath.Join(paths.InputsDir, "party.yml"), []byte("changed"), 0o664); err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
if _, err := collectPublishPreparedInputs(env.ArtifactStore, paths, runRoot, m.Inputs); err == nil {
|
||||||
|
t.Fatal("accepted changed prepared input")
|
||||||
|
}
|
||||||
|
after, err := os.ReadFile(archivedParty)
|
||||||
|
if err != nil || string(after) != string(before) {
|
||||||
|
t.Fatalf("changed archive after failed validation: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,6 +14,7 @@ import (
|
|||||||
|
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
"gitea.maximumdirect.net/eric/narratio/internal/artifacts"
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
"gitea.maximumdirect.net/eric/narratio/internal/config"
|
||||||
|
"gitea.maximumdirect.net/eric/narratio/internal/fileops"
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
|
"gitea.maximumdirect.net/eric/narratio/internal/manifest"
|
||||||
"gitea.maximumdirect.net/eric/narratio/internal/pathsafe"
|
"gitea.maximumdirect.net/eric/narratio/internal/pathsafe"
|
||||||
)
|
)
|
||||||
@@ -46,17 +47,9 @@ func collectPublishPreparedInputs(store artifacts.Store, paths artifacts.Session
|
|||||||
_ = source.Close()
|
_ = source.Close()
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
data, err := io.ReadAll(source)
|
|
||||||
closeErr := source.Close()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if closeErr != nil {
|
|
||||||
return nil, closeErr
|
|
||||||
}
|
|
||||||
archive := filepath.ToSlash(filepath.Join("prepare", "inputs", name))
|
archive := filepath.ToSlash(filepath.Join("prepare", "inputs", name))
|
||||||
destination := filepath.Join(runRoot, filepath.FromSlash(archive))
|
destination := filepath.Join(runRoot, filepath.FromSlash(archive))
|
||||||
if _, err := writeBytesIfChanged(store, destination, data); err != nil {
|
if err := archivePreparedPublishInput(store, source, destination, record.Checksum); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
result = append(result, publishUploadFile{RelativePath: archive, SourceRelativePath: archive, Checksum: record.Checksum})
|
result = append(result, publishUploadFile{RelativePath: archive, SourceRelativePath: archive, Checksum: record.Checksum})
|
||||||
@@ -64,6 +57,26 @@ func collectPublishPreparedInputs(store artifacts.Store, paths artifacts.Session
|
|||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// archivePreparedPublishInput consumes and closes the verified source descriptor.
|
||||||
|
func archivePreparedPublishInput(store artifacts.Store, source *os.File, destination, checksum string) (resultErr error) {
|
||||||
|
defer func() { resultErr = errors.Join(resultErr, source.Close()) }()
|
||||||
|
exists, err := store.Exists(destination)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if exists {
|
||||||
|
current, err := store.Checksum(destination)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if strings.EqualFold(current, checksum) {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_, err = fileops.WriteReaderAtomicWithChecksum(destination, source, fileops.WorkspaceFileMode)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
func collectPublishRunFiles(runRoot string, sessionManifest *manifest.Manifest) ([]publishUploadFile, error) {
|
func collectPublishRunFiles(runRoot string, sessionManifest *manifest.Manifest) ([]publishUploadFile, error) {
|
||||||
if sessionManifest == nil {
|
if sessionManifest == nil {
|
||||||
return nil, fmt.Errorf("session manifest is required")
|
return nil, fmt.Errorf("session manifest is required")
|
||||||
|
|||||||
Reference in New Issue
Block a user