test(build): run Go integration tests against a real BuildKit

Aperta
#65 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
42/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
docker, github-actions, go

Direzione di ricerca

Start with pkg/build/build_test.go, the Dockerfile, and the Makefile; compare dalec's test/testenv/buildx.go and build.go for the BuildKit connection and frontend-input flow. Then implement the tagged integration package and four fixture tests, add make test-integration, CI, and guidance in docs/development.md. Done means the integration tests pass on default and selected builders, CI runs them, and go test ./... still works without Docker.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

area/build enhancement testing

Problem

AgentKit's Go tests for the build (pkg/build/build_test.go) use fakeBuildClient, a stand-in for BuildKit. They're fast, but they can't show what BuildKit actually does with AgentKit's output:

  • the image settings that get exported;
  • the files that end up in the image;
  • multi-platform results;
  • attestations;
  • build steps that run commands;
  • network settings and cache behavior.

Real builds are only checked by shell scripts and CI jobs (scripts/*.sh and the Docker jobs in .github/workflows/ci.yml). Those need make build-agentkit to build the frontend image and --load it first. Their checks are written in bash, and they're slow to extend.

Several planned features can only really be proven against a real BuildKit:

Issue What only a real build can show
#55 the attestation is attached
#57 test steps run with network off, and the image stays unchanged
#58 what --call actually returns
#61 the cache is reused
#62 what the debug target actually outputs
#63 npm scripts really run offline
#64 the runtime image is swapped

dalec solves this with Go integration tests that use a real BuildKit through the current docker buildx builder:

  • each test builds the frontend from the repo's source inside BuildKit and hands it in directly, so no frontend image is built, pushed or loaded first;
  • the test then checks the real result in Go.

See dalec's test/testenv/:

  • buildx.go connects through docker buildx dial-stdio;
  • build.go builds the frontend (buildBaseFrontend) and passes it in (injectInput, withDalecInput).

What

  • A new test package, for example test/integration/, behind a build tag (//go:build integration). Plain go test ./... stays fast and keeps working without Docker.
  • make test-integration runs it against the current buildx builder. An env var such as AGENTKIT_TEST_BUILDER picks a different builder, for example a remote one.
  • A small helper (test/integration/testenv) that:
    • connects to the builder through docker buildx dial-stdio;
    • builds the AgentKit frontend from the repo's Dockerfile inside BuildKit;
    • builds a given Agentkitfile with that frontend and returns the result so tests can read files, image settings and metadata.
  • First tests, covering what exists today:
    1. test/agentkitfile-hello.yaml builds. The image settings have user 1000:1000, the right entrypoint, the exposed ports and the AgentKit labels. /agent/agent.yaml in the image matches abi.Render.
    2. Instructions from a file in the build context end up in /agent/agent.yaml.
    3. A two-platform build returns one image per platform and the right platform list.
    4. An invalid Agentkitfile fails with the expected message.
  • A CI job that runs these tests on a docker-container builder.
  • Future feature PRs (#55, #57, #58, #61, #62, #63, #64) add their tests here.
Runtime images in tests

A real agent build starts from a runtime image.

  • Tests that don't run the agent: use the published runtime image pinned by digest, or a tiny stand-in image, to keep them fast.
  • Tests that do run the agent, such as #57: build the runtime image from runtimes/<runtime>/Dockerfile in the same BuildKit and pass it in through the agentkit-runtime build context from #64.
Out of scope
  • Measuring code coverage of the frontend while it runs inside BuildKit. Dalec does this in test/testenv/frontend_coverage.go; it's a good follow-up.
  • Replacing the existing shell smoke tests. They can move over gradually.
License note

Dalec is Apache-2.0 and AgentKit is MIT. Prefer writing the small helper fresh with dalec as a guide. If you copy code, keep dalec's license notice with it.

Why

  • New features can be proven against a real BuildKit, in Go, next to the code they test.
  • No frontend image has to be built, loaded or pushed before testing.
  • It works with any builder, including remote ones.
  • Bugs that only show up in real builds get caught early, such as missing attestations, wrong image settings or broken multi-platform output.

How

Where things are
File What it does
pkg/build/build_test.go Today's tests with fakeBuildClient. Keep them.
Dockerfile Builds the frontend: a static Go binary at /bin/agentkit in an empty image.
Makefile build-agentkit, build-test-agent. Add test-integration.
.github/workflows/ci.yml Docker jobs. Actions are pinned by commit SHA; do the same.
dalec test/testenv/buildx.go dialStdio: connecting to a buildx builder, including keepalive so a dead connection is noticed.
dalec test/testenv/build.go buildBaseFrontend, injectInput, withDalecInput, withProjectRoot, testWriter.
Steps
  1. Connect.
    • Start docker buildx dial-stdio, adding --builder <name> when AGENTKIT_TEST_BUILDER is set.
    • Create a BuildKit client over it with client.New(ctx, "", client.WithContextDialer(...)).
    • If docker buildx isn't available, skip with a clear message.
  2. Build the frontend.
    • Inside a client.Build(...) call, solve the repo's Dockerfile with BuildKit's built-in dockerfile.v0 frontend, using the repo root as the local context.
    • Dalec's withProjectRoot shows how to find the root.
  3. Hand it in and build the fixture.
    • Add the frontend result as an input: SolveRequest.FrontendInputs[id] plus FrontendOpt["context:"+id] = "input:"+id.
    • Then solve with Frontend: "gateway.v0" and FrontendOpt["source"] = id.
    • Point the context and dockerfile local inputs at the fixture folder, and set FrontendOpt["filename"].
  4. Read results. Add small helpers that:
    • read a file from a result with ref.ReadFile;
    • decode the image settings from metadata exptypes.ExporterImageConfigKey (per platform for multi-platform builds);
    • read the platform list from exptypes.ExporterPlatformsKey.
  5. Logs. Collect build output and print it with t.Log only when a test fails, as dalec's testWriter does.
  6. CI.
    • Add a job that uses docker/setup-buildx-action (pinned by SHA) to create a docker-container builder, then runs make test-integration.
    • Run actionlint after editing workflows (see AGENTS.md).
  7. Docs. Add a section to docs/development.md on running the tests locally, choosing a builder, and adding a test for a new feature.
Tests

The four tests listed under What are the deliverable. Run:

go test ./...                 # unchanged; needs no Docker
make test-integration         # new; needs docker buildx
make lint

Done when

  • make test-integration passes locally on Docker's default builder and on a docker-container builder, without building or loading the frontend image first.
  • AGENTKIT_TEST_BUILDER points the tests at another builder.
  • CI runs the integration tests.
  • go test ./... still runs without Docker.
  • docs/development.md explains how to run and extend the tests.
Lingua principale
Python
Stelle
7
Fork
5
Merge medio
3h 39m
PR unite (30g)
1

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di orka-agents/agentkit

Tutte le issue di orka-agents/agentkit

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.