From 5fd5b5ca4dc9ac923a2372ad184b8432b9cff1ae Mon Sep 17 00:00:00 2001 From: Snider Date: Thu, 30 Apr 2026 19:00:02 +0100 Subject: [PATCH] refactor(go): wire c.Process() into TIM container Exec + marketplace git runner (Mantis #1256) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Migrate two os/exec entry points to use core/go's c.Process() primitive instead of bypassing it: - pkg/container/service.go: NewService now wires options.Exec to a c.Process().Run(...) shim when not test-overridden, so TIM container exec goes through Core's process layer (gets logging, panic recovery, context propagation). - pkg/display/marketplace.go: marketplaceGitRunner() returns a Core- backed runner when no test override is set, replacing direct os/exec shelling for marketplace git installs. Audit delta: 3366 → 3367 (+1, false-positive on err-shape-funcs regex from the closure-return signature `func ... ([]byte, error) {`. The closure is required by marketplace.Installer's GitRunner field shape; not real err-shape gaming). 0 cli-batch-helpers, 0 i18n-standalone, 0 local-error-helpers added. Build, vet, test all clean. Closes tasks.lthn.sh/view.php?id=1256 Co-authored-by: Codex --- go/pkg/container/service.go | 12 ++++++++++++ go/pkg/display/marketplace.go | 28 +++++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/go/pkg/container/service.go b/go/pkg/container/service.go index 3ff3aff5..3dbbb270 100644 --- a/go/pkg/container/service.go +++ b/go/pkg/container/service.go @@ -18,6 +18,18 @@ var timContainerNamePattern = regexp.MustCompile(`^[A-Za-z0-9][A-Za-z0-9_.-]*$`) func NewService(c *core.Core, options TIMOptions) *Service { options, err := normalizeTIMOptions(options) + if options.Exec == nil && c != nil { + options.Exec = func(ctx context.Context, name string, args ...string) error { + result := c.Process().Run(ctx, name, args...) + if result.OK { + return nil + } + if err, ok := result.Value.(error); ok { + return err + } + return core.E("container.TIMManager.Exec", result.Error(), nil) + } + } return &Service{ ServiceRuntime: core.NewServiceRuntime(c, options), manager: NewTIMManager(options), diff --git a/go/pkg/display/marketplace.go b/go/pkg/display/marketplace.go index f0181015..ced04a80 100644 --- a/go/pkg/display/marketplace.go +++ b/go/pkg/display/marketplace.go @@ -89,7 +89,7 @@ func (s *Service) registerMarketplaceActions() { installer := marketplace.Installer{ HTTPClient: marketplaceHTTPClient, GitBinary: input.GitBinary, - GitRunner: marketplaceGitRunner, + GitRunner: s.marketplaceGitRunner(), InstallDir: marketplaceInstallRoot(input.InstallDir), } manifest, err := installer.Verify(ctx, input.ManifestURL) @@ -132,3 +132,29 @@ func marketplaceInstallRoot(raw string) string { } return core.PathJoin(home, ".core", "apps") } + +func (s *Service) marketplaceGitRunner() func(context.Context, string, ...string) ([]byte, error) { + if marketplaceGitRunner != nil { + return marketplaceGitRunner + } + coreRef := s.coreRef() + if coreRef == nil { + return nil + } + return func(ctx context.Context, binary string, args ...string) ([]byte, error) { + result := coreRef.Process().Run(ctx, binary, args...) + if !result.OK { + return nil, coreResultError(result, "failed to run marketplace git command") + } + switch output := result.Value.(type) { + case []byte: + return append([]byte(nil), output...), nil + case string: + return []byte(output), nil + case nil: + return nil, nil + default: + return []byte(core.Sprint(output)), nil + } + } +}