返回 DeepSeek-Reasonix
project_program_verify.go
根目录 / internal / config / project_program_verify.go
1 package config
2
3 import (
4 "errors"
5 "fmt"
6 )
7
8 // ErrProjectProgramChanged is an approved program whose files changed after
9 // the approval was checked, so the host refuses to run it.
10 var ErrProjectProgramChanged = errors.New("workspace program changed since it was approved")
11
12 // Verify reports ErrProjectProgramChanged when a file the approval covered no
13 // longer holds the approved content.
14 func (p ProjectProgram) Verify() error {
15 if len(p.Files) == 0 || p.currentDigest() == p.Digest {
16 return nil
17 }
18 return fmt.Errorf("%w: %s %q; approve it again with `reasonix trust`", ErrProjectProgramChanged, p.Kind, p.Name)
19 }
20
21 // ProjectProgramVerifier returns the check an executor runs before starting the
22 // project-declared program of kind and name, or nil when the program in force
23 // is not one a workspace declared.
24 func (c *Config) ProjectProgramVerifier(kind ProjectProgramKind, name string) func() error {
25 if c == nil {
26 return nil
27 }
28 for _, p := range c.projectScope.admitted {
29 if p.Kind == kind && p.Name == name && len(p.Files) > 0 {
30 return p.Verify
31 }
32 }
33 return nil
34 }
35
35 lines GO