Use stable verified Notarius reference snapshots

This commit is contained in:
2026-09-16 17:53:29 +00:00
parent 5202f16972
commit e13d87a077
8 changed files with 469 additions and 101 deletions

View File

@@ -10,6 +10,8 @@ import (
"gitea.maximumdirect.net/eric/narratio/internal/pathsafe"
)
const sha256HexLength = 64
// SessionPaths contains canonical local paths for one session work directory.
type SessionPaths struct {
WorkspaceRoot string
@@ -28,6 +30,7 @@ type SessionPaths struct {
CurrentDir string
RunsDir string
PreviousDir string
CacheDir string
PreviousManifestPath string
PreviousArtifactsDir string
ManifestPath string
@@ -108,17 +111,37 @@ func SessionRunNotariusLogPathForCampaign(rootDir, campaign, sessionID, runID st
return filepath.Join(SessionRunExtractDirForCampaign(rootDir, campaign, sessionID, runID), "notarius.stderr.log")
}
// SessionRunNotariusReferencesDirForCampaign returns the invocation-local
// directory containing verified reference snapshots supplied to Notarius.
func SessionRunNotariusReferencesDirForCampaign(rootDir, campaign, sessionID, runID string) string {
return filepath.Join(SessionRunExtractDirForCampaign(rootDir, campaign, sessionID, runID), "references")
}
// SessionRunNotariusOutputRootForCampaign returns the invocation-local Notarius output root.
func SessionRunNotariusOutputRootForCampaign(rootDir, campaign, sessionID, runID string) string {
return filepath.Join(SessionRunExtractDirForCampaign(rootDir, campaign, sessionID, runID), "notarius-output")
}
// SessionNotariusReferenceCacheDir returns the stable cache root for verified
// reference snapshots supplied to Notarius.
func SessionNotariusReferenceCacheDir(paths SessionPaths) string {
return filepath.Join(paths.CacheDir, "notarius", "references")
}
// SessionNotariusReferenceSnapshotPath returns the content-addressed path for
// one verified prepared reference snapshot.
func SessionNotariusReferenceSnapshotPath(paths SessionPaths, checksum, preparedBasename string) (string, error) {
if len(checksum) != sha256HexLength {
return "", fmt.Errorf("reference checksum must be a full lowercase SHA-256 digest")
}
for _, character := range checksum {
if (character < '0' || character > '9') && (character < 'a' || character > 'f') {
return "", fmt.Errorf("reference checksum must be a full lowercase SHA-256 digest")
}
}
if err := pathsafe.ValidateOpaqueSegment(preparedBasename); err != nil {
return "", fmt.Errorf("prepared reference basename: %w", err)
}
return pathsafe.JoinSlashRelativeUnderRoot(
SessionNotariusReferenceCacheDir(paths),
checksum+"/"+preparedBasename,
)
}
// SessionNotariusBundleDirForCampaign returns one immutable durable bundle destination.
func SessionNotariusBundleDirForCampaign(rootDir, campaign, sessionID, runID string) string {
return filepath.Join(
@@ -268,6 +291,7 @@ func buildSessionPathsFromRoot(workspaceRoot, campaign, sessionID, root string)
CurrentDir: filepath.Join(root, config.PathCurrentDirSegment),
RunsDir: filepath.Join(root, config.PathRunsDirSegment),
PreviousDir: filepath.Join(root, config.PathPreviousDirSegment),
CacheDir: filepath.Join(root, config.PathCacheDirSegment),
PreviousManifestPath: filepath.Join(root, config.PathPreviousDirSegment, config.PathManifestFile),
PreviousArtifactsDir: filepath.Join(root, config.PathPreviousDirSegment, config.PathArtifactsDirSegment),
ManifestPath: filepath.Join(root, config.PathManifestFile),