Skip to content

feat(plugin): wire before_build and after_build hooks - #59

Merged
ademboukabes merged 3 commits into
developfrom
feat/plugin-build-hooks
Oct 13, 2026
Merged

ademboukabes merged 3 commits into
developfrom
feat/plugin-build-hooks

Conversation

@ademboukabes

Copy link
Copy Markdown
Collaborator

Summary

Closes #39.

Follow-up to the plugin system foundation (PR #38). Extends the lifecycle plugin architecture to mctf build by dispatching before_build and after_build hooks.

What changed

  1. Protocol & Payloads (internal/plugin/):

    • Added hook constants HookBeforeBuild = "before_build" and HookAfterBuild = "after_build".
    • Defined typed BuildPayload (event, phase, sha, no_cache, push, dry_run, images, outcome, error) and BuildImage (challenge, category, slug, tags, labels).
    • Extended TestHelperProcess in internal/plugin/plugin_test.go to subscribe to build hooks.
    • Added TestManager_BuildHooksDelivered unit test verifying end-to-end delivery of build hooks over JSON-RPC.
  2. CLI Wiring (cmd/build.go):

    • Initialized plugin manager via plugin.Load using cfg.Plugins.
    • Added deferred pm.Close() for clean subprocess shutdown.
    • Dispatched before_build prior to image builds (build.Apply).
    • Dispatched after_build with outcome "failed" upon build error, scan leak failure, or push failure.
    • Dispatched after_build with outcome "success" upon successful completion.
    • Maintained strict crash isolation: plugin failures or timeouts never abort mctf build.
    • Added unit tests in cmd/build_plugin_test.go.
  3. Documentation & Reference Plugin:

    • Updated docs/spec/plugins.md hook roster marking before_build and after_build as shipped.
    • Added JSON payload schema for build hooks.
    • Updated reference plugin examples/sample-event/plugins/logger.sh to subscribe to and log build hooks.
    • Updated docs/BACKLOG.md tracking.

Verification

  • make lint (golangci-lint run ./... + go vet ./...) ✅ (0 issues)
  • go test -race ./... ✅ (100% tests pass)
  • make build ✅
  • ./mctf -C examples/sample-event validate ✅
  • ./mctf -C examples/sample-event generate --check ✅
  • python3 scripts/validate-examples.py ✅
  • python3 scripts/validate-generated.py ✅

- Add HookBeforeBuild and HookAfterBuild constants in protocol.go.
- Define BuildPayload and BuildImage structs matching build.ImageSpec data.
- Update TestHelperProcess and add TestManager_BuildHooksDelivered test.
- Load lifecycle plugins via plugin.Load using cfg.Plugins.
- Dispatch before_build prior to build.Apply with ImageSpec details.
- Dispatch after_build with outcome failed on build, scan, or push failure.
- Dispatch after_build with outcome success on completion.
- Add buildHookPayload helper and unit tests in cmd/build_plugin_test.go.
- Mark before_build and after_build hooks as shipped in docs/spec/plugins.md.
- Document Build payload schema with JSON example.
- Update examples/sample-event/plugins/logger.sh to subscribe and log build hooks.
- Update docs/BACKLOG.md tracking.
@ademboukabes
ademboukabes merged commit 25c671e into develop Oct 13, 2026
3 checks passed
@ademboukabes
ademboukabes deleted the feat/plugin-build-hooks branch October 13, 2026 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant