From 75b835a3731b76d32f0d166e49ea06ee71cd171f Mon Sep 17 00:00:00 2001 From: Abhinav Deval Date: Mon, 23 Nov 2026 18:27:44 +0530 Subject: [PATCH] fix: use single copy of core spec from profiler Consolidate the core spec into a single source of truth embedded in the linked Go profiler, and have the CLI validator read it from there. - Read core schema via extensioncheck.InstalledCoreSchema() in internal/validate - Remove duplicate -X flag for internal/validate.coreSchemaBase64 from build.go and release-package.py - Update embed guard test to assert only the profiler variable is embedded - Bump go-rc-profiler to v0.9.0 and update distribution/components.lock.yaml Closes #15 Signed-off-by: Abhinav Deval --- distribution/components.lock.yaml | 28 ++++++++++++++-------------- go.mod | 11 +++++++---- go.sum | 10 ++-------- internal/validate/core.go | 15 +++++---------- internal/validate/embed_test.go | 21 +++++++++++++-------- scripts/build.go | 3 +-- scripts/release-package.py | 7 +++---- 7 files changed, 45 insertions(+), 50 deletions(-) diff --git a/distribution/components.lock.yaml b/distribution/components.lock.yaml index 46db7f1..1a7dd4b 100644 --- a/distribution/components.lock.yaml +++ b/distribution/components.lock.yaml @@ -3,8 +3,8 @@ extensions: repository: https://github.com/runtimeconditions/extensions.git commit: dd96ddaebb0d29d882212d6ccc10c130f3ff2ddf goProfiler: - version: v0.8.0 - commit: 179ca557c05ab2b64fd5c184f4550ce4182e2f9b + version: v0.9.0 + commit: 324969e718e6fdaf3ebe3ca40e3beb4b735cd587 protocol: go-profiler-argv/v1 coreSchema: version: 0.4.0 @@ -13,18 +13,18 @@ goProfiler: sha256: 96d430c7936fcf7334aa9613f63bb306592e07cf56fe4154af57933d2c1480e6 platforms: darwin/amd64: - url: https://github.com/runtimeconditions/go-rc-profiler/releases/download/v0.8.0/go-rc-profiler_v0.8.0_darwin_amd64.tar.gz - archiveSHA256: adc04f96520f1fe4667a4c82b6e84b817f3fe983e6fc3e14df557f9886e8167a - executableSHA256: 8eb75067f391ebad1d84139bc1d6af382a7aaee4f96ee6b32d4fa0057857216a + url: https://github.com/runtimeconditions/go-rc-profiler/releases/download/v0.9.0/go-rc-profiler_v0.9.0_darwin_amd64.tar.gz + archiveSHA256: 7ed3f88a7dbc282586507e2a31c7954fdb4113d15880be8a510b6928e5113716 + executableSHA256: ca0a79e52ea5af98eecdf6030bef2b011f6ddd9fdd534aed8bbe8db1ff50dfa5 darwin/arm64: - url: https://github.com/runtimeconditions/go-rc-profiler/releases/download/v0.8.0/go-rc-profiler_v0.8.0_darwin_arm64.tar.gz - archiveSHA256: fbd7c2ed2eaf074b0b79a9bb49b977217c7e3e7cbf3ae518b388a6386ec298bb - executableSHA256: ba9692dfc535ae00670a418d640c23fbcadd69895d3c829f24a3cb375636e035 + url: https://github.com/runtimeconditions/go-rc-profiler/releases/download/v0.9.0/go-rc-profiler_v0.9.0_darwin_arm64.tar.gz + archiveSHA256: f968e527edb7bd7ce42aacb57a0ce57b4cee01de3a5fa184ca0482e5cec05b6f + executableSHA256: e90d7271b56c5ef47c0fbb7dba243f040819eb6502a7e78ba7eb129a4771d326 linux/amd64: - url: https://github.com/runtimeconditions/go-rc-profiler/releases/download/v0.8.0/go-rc-profiler_v0.8.0_linux_amd64.tar.gz - archiveSHA256: 337fe2d9579461779aa823f7ef0b9228ae307ec8da1ebd8a20c576edb3b88b13 - executableSHA256: baf2104ce45371bd1490d3002adaa9d5f7e2e8f03a94b57fc2526e0ae4ae2466 + url: https://github.com/runtimeconditions/go-rc-profiler/releases/download/v0.9.0/go-rc-profiler_v0.9.0_linux_amd64.tar.gz + archiveSHA256: 60b2cdc54bdde168275768171e9282daef5a227448acc2d2a81137f5c20f900e + executableSHA256: 607e61789c6ef10e72a25523d8e6dab23eb93acc931d1d8da7322f60731e4e84 linux/arm64: - url: https://github.com/runtimeconditions/go-rc-profiler/releases/download/v0.8.0/go-rc-profiler_v0.8.0_linux_arm64.tar.gz - archiveSHA256: 445d1458a555fe340661ee3a830b62b67c30b59912fec29c96f22c3e0974b65e - executableSHA256: 4f9fa86cc386829d1fddacf59400ab1fc89d65e81ce86d83d6aedf2c30a1c6a9 + url: https://github.com/runtimeconditions/go-rc-profiler/releases/download/v0.9.0/go-rc-profiler_v0.9.0_linux_arm64.tar.gz + archiveSHA256: 168aeb712340d5098b1e6d07bec3989775595ae1066e8e16173560c95228d657 + executableSHA256: 074efd93fb52e32af867f1e0f2df5fe4d70011e335b323829c73b4c5131529f0 diff --git a/go.mod b/go.mod index 96a9c3d..27d6dc8 100644 --- a/go.mod +++ b/go.mod @@ -5,19 +5,22 @@ go 1.25.0 toolchain go1.26.5 require ( - github.com/runtimeconditions/extensions/tooling/extension-bindings/emitters/go v0.0.0-20261111072413-dd96ddaebb0d - github.com/runtimeconditions/extensions/tooling/extension-bindings/normalizer v0.0.0-20261111072413-dd96ddaebb0d github.com/runtimeconditions/extensions/tooling/extension-bindings/orchestrator v0.0.0-20261111072413-dd96ddaebb0d - github.com/runtimeconditions/go-rc-profiler v0.8.0 + github.com/runtimeconditions/go-rc-profiler v0.9.0 github.com/spf13/cobra v1.10.2 go.yaml.in/yaml/v3 v3.0.4 golang.org/x/mod v0.28.0 ) +require ( + github.com/runtimeconditions/extensions/tooling/extension-bindings/emitters/go v0.0.0-20261111072413-dd96ddaebb0d // indirect + github.com/runtimeconditions/extensions/tooling/extension-bindings/normalizer v0.0.0-20261111072413-dd96ddaebb0d // indirect +) + require ( github.com/inconshreveable/mousetrap v1.1.0 // indirect github.com/santhosh-tekuri/jsonschema/v6 v6.0.3 - github.com/spf13/pflag v1.0.9 // indirect + github.com/spf13/pflag v1.0.9 golang.org/x/sync v0.17.0 // indirect golang.org/x/text v0.14.0 // indirect golang.org/x/tools v0.37.0 // indirect diff --git a/go.sum b/go.sum index 9dbcaa4..24071e0 100644 --- a/go.sum +++ b/go.sum @@ -11,14 +11,8 @@ github.com/runtimeconditions/extensions/tooling/extension-bindings/normalizer v0 github.com/runtimeconditions/extensions/tooling/extension-bindings/normalizer v0.0.0-20261111072413-dd96ddaebb0d/go.mod h1:cvsEa8JK0QyejCnMpu37euVabv3EYn29y5Z9Ep0bUQc= github.com/runtimeconditions/extensions/tooling/extension-bindings/orchestrator v0.0.0-20261111072413-dd96ddaebb0d h1:inJH3dFBlD6flxgy8VANdvwPOgQrFv5vsDt1MF83ook= github.com/runtimeconditions/extensions/tooling/extension-bindings/orchestrator v0.0.0-20261111072413-dd96ddaebb0d/go.mod h1:57G6oeRpB8qTceNnLYZmIavqukZsSwTK7P0EZMeJJxc= -github.com/runtimeconditions/go-rc-profiler v0.6.1 h1:lFatYU891EnZs5+N24HvzyLJ511+CrSKvg1iTOG4G0U= -github.com/runtimeconditions/go-rc-profiler v0.6.1/go.mod h1:zQSOr50hlFxqJL2AaF3BpgTMbOlykey9OBa17E/jWFA= -github.com/runtimeconditions/go-rc-profiler v0.7.0 h1:u78auPN14C9LRnZKoRFp3ZdjBOv7NNAzKjCXmtaS80s= -github.com/runtimeconditions/go-rc-profiler v0.7.0/go.mod h1:zQSOr50hlFxqJL2AaF3BpgTMbOlykey9OBa17E/jWFA= -github.com/runtimeconditions/go-rc-profiler v0.7.1 h1:tsnyrkgEYmgnmpuUK2SEwhWPZ2BFUxw5qIYPEBYoQ7I= -github.com/runtimeconditions/go-rc-profiler v0.7.1/go.mod h1:zQSOr50hlFxqJL2AaF3BpgTMbOlykey9OBa17E/jWFA= -github.com/runtimeconditions/go-rc-profiler v0.8.0 h1:D8MYXh+DNBPTbqNxxi4yRsyiskuUvGsjcZd3Nm/ORSQ= -github.com/runtimeconditions/go-rc-profiler v0.8.0/go.mod h1:zQSOr50hlFxqJL2AaF3BpgTMbOlykey9OBa17E/jWFA= +github.com/runtimeconditions/go-rc-profiler v0.9.0 h1:H1kNplezFnP5SJ9d/uzcgBC5vP6KmAA7BXQoV+ITqng= +github.com/runtimeconditions/go-rc-profiler v0.9.0/go.mod h1:zQSOr50hlFxqJL2AaF3BpgTMbOlykey9OBa17E/jWFA= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/santhosh-tekuri/jsonschema/v6 v6.0.3 h1:1EYB5IzjZawrrnELUi78f9fPu57HuXjmddZPjrls/28= github.com/santhosh-tekuri/jsonschema/v6 v6.0.3/go.mod h1:JXeL+ps8p7/KNMjDQk3TCwPpBy0wYklyWTfbkIzdIFU= diff --git a/internal/validate/core.go b/internal/validate/core.go index ded7f71..9a40454 100644 --- a/internal/validate/core.go +++ b/internal/validate/core.go @@ -1,19 +1,14 @@ package validate import ( - "encoding/base64" "errors" "fmt" + "github.com/runtimeconditions/go-rc-profiler/extensioncheck" "github.com/santhosh-tekuri/jsonschema/v6" "go.yaml.in/yaml/v3" ) -// coreSchemaBase64 is set by the release build from the separately versioned core profile schema, -// after its SHA-256 has been checked (scripts/build.go). A plain go build leaves it empty and -// validation fails closed, because a profile cannot be called valid without the core schema. -var coreSchemaBase64 string - var coreSchemaOverride []byte // UseCoreSchema makes the validator use the given core profile schema instead of the one the build @@ -26,14 +21,14 @@ var errNoCoreSchema = errors.New("this build of rc has no verified core profile func loadCoreSchema() (*jsonschema.Schema, error) { data := coreSchemaOverride if len(data) == 0 { - if coreSchemaBase64 == "" { + schema, err := extensioncheck.InstalledCoreSchema() + if errors.Is(err, extensioncheck.ErrNoInstalledCoreSchema) { return nil, errNoCoreSchema } - decoded, err := base64.StdEncoding.DecodeString(coreSchemaBase64) if err != nil { - return nil, fmt.Errorf("the embedded core profile schema is not valid base64: %w", err) + return nil, err } - data = decoded + data = schema } var document map[string]any if err := yaml.Unmarshal(data, &document); err != nil { diff --git a/internal/validate/embed_test.go b/internal/validate/embed_test.go index 7d59d47..9b8c0a6 100644 --- a/internal/validate/embed_test.go +++ b/internal/validate/embed_test.go @@ -6,19 +6,24 @@ import ( "testing" ) -// Both ways of building rc embed the core schema through linker flags: scripts/build.go for local -// and CI builds, scripts/release-package.py for the release archives and packages. The release -// build once set only the Go profiler's variable, so a released rc refused to validate. CI builds -// with build.go only, so nothing else would notice that again. -func TestEveryBuildEmbedsTheCoreSchemaInTheValidator(t *testing.T) { - const variable = "github.com/runtimeconditions/rc-cli/internal/validate.coreSchemaBase64" +// Both ways of building rc embed the core schema into the linked Go profiler: scripts/build.go +// for local and CI builds, scripts/release-package.py for the release archives and packages. +// rc's validator reads that copy through go-rc-profiler/extensioncheck.InstalledCoreSchema, so +// neither build script should embed a second copy in internal/validate. +func TestEveryBuildEmbedsOnlyTheProfilerCoreSchema(t *testing.T) { + const profilerVar = "github.com/runtimeconditions/go-rc-profiler/extensioncheck.installedCoreSchemaBase64" + const validatorVar = "github.com/runtimeconditions/rc-cli/internal/validate.coreSchemaBase64" for _, script := range []string{"../../scripts/build.go", "../../scripts/release-package.py"} { data, err := os.ReadFile(script) if err != nil { t.Fatal(err) } - if !strings.Contains(string(data), variable) { - t.Errorf("%s does not set %s, so a build made with it cannot validate profiles", script, variable) + content := string(data) + if !strings.Contains(content, profilerVar) { + t.Errorf("%s does not set %s, so a build made with it cannot validate profiles", script, profilerVar) + } + if strings.Contains(content, validatorVar) { + t.Errorf("%s still sets obsolete %s; only the profiler variable should be embedded", script, validatorVar) } } } diff --git a/scripts/build.go b/scripts/build.go index 7bc5b26..1872a03 100644 --- a/scripts/build.go +++ b/scripts/build.go @@ -73,8 +73,7 @@ func build() error { } encoded := base64.StdEncoding.EncodeToString(schema) linkerFlags := "-X main.version=" + *version + " -X main.commit=" + *commit + - " -X github.com/runtimeconditions/go-rc-profiler/extensioncheck.installedCoreSchemaBase64=" + encoded + - " -X github.com/runtimeconditions/rc-cli/internal/validate.coreSchemaBase64=" + encoded + " -X github.com/runtimeconditions/go-rc-profiler/extensioncheck.installedCoreSchemaBase64=" + encoded command := exec.Command("go", "build", "-trimpath", "-ldflags", linkerFlags, "-o", *output, "./cmd/rc") command.Stdin, command.Stdout, command.Stderr = os.Stdin, os.Stdout, os.Stderr return command.Run() diff --git a/scripts/release-package.py b/scripts/release-package.py index 45818bc..96a5c61 100644 --- a/scripts/release-package.py +++ b/scripts/release-package.py @@ -125,12 +125,11 @@ def main(): env = dict(os.environ, CGO_ENABLED="0", GOOS=goos, GOARCH=goarch) binary = work / target / "bin/rc" binary.parent.mkdir(parents=True) - # The core schema is embedded twice: for the linked Go profiler and for rc's own validator. - # scripts/build.go sets the same two variables. + # The core schema is embedded once into the linked Go profiler; rc's validator reads it from there. + # scripts/build.go sets the same variable. encoded_schema = base64.b64encode(core_schema).decode("ascii") linker_flags = "-X main.version=" + args.version + " -X main.commit=" + args.commit + \ - " -X github.com/runtimeconditions/go-rc-profiler/extensioncheck.installedCoreSchemaBase64=" + encoded_schema + \ - " -X github.com/runtimeconditions/rc-cli/internal/validate.coreSchemaBase64=" + encoded_schema + " -X github.com/runtimeconditions/go-rc-profiler/extensioncheck.installedCoreSchemaBase64=" + encoded_schema run(["go", "build", "-trimpath", "-buildvcs=false", "-ldflags", linker_flags, "-o", str(binary), "./cmd/rc"], env=env) prefix = work / target / "prefix"