test(build): check that the same Agentkitfile always produces the same build

Aperta
#61 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
68/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
docker, go

Direzione di ricerca

Start with pkg/agentkit2llb/agent/convert.go, pkg/agentkit2llb/agent/image.go, and pkg/agentkit/abi/render.go, then read dalec's determinism_test.go for the reusable-helper example. Build a map-heavy fixture and check repeated Agentkit2LLB definitions, NewImageConfig JSON, and abi.Render bytes; run the listed Go tests and make lint. Done means all three outputs are byte-identical across runs and any differences found are fixed.

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

Descrizione

area/build enhancement good first issue testing

Problem

BuildKit only reuses cached work when a build step is byte-for-byte the same as last time. In Go, looping over a map visits the keys in a random order. If any code builds a build step, the image settings or /agent/agent.yaml by looping over a map, two builds of the same Agentkitfile can come out different.

When that happens:

  • The cache misses. Rebuilds redo work for no reason.
  • Identical input, different images. The same file produces images with different digests.
  • The config digest changes. Orka (ACP mode) and the agentsessions profile pin the SHA-256 of the exact /agent/agent.yaml bytes. If the file's order changed between builds, that digest would change too.
  • #55 breaks. It promises that the same file always produces the same manifest.

This kind of bug is silent: every build still succeeds.

The risk is small today, because the build is just "runtime image + /agent/agent.yaml". But new features add more build output that comes from maps: install steps with env vars (#54), test steps (#57) and manifest attestations (#55).

dalec guards against this with determinism_test.go. It builds the same thing many times and checks that the results are identical.

What

Add tests that build the same agent many times and require byte-identical results for:

  1. the build steps: the marshaled BuildKit definition from Agentkit2LLB;
  2. the image settings from NewImageConfig (labels, env, ports);
  3. the /agent/agent.yaml bytes from abi.Render.

Fix any differences the tests find, usually by sorting keys before looping. Make the helper easy to reuse, so #54, #55 and #57 can add their own output to these checks.

Out of scope
  • Reproducing builds across different machines or BuildKit versions.
  • Changing what the build produces.

Why

  • Reliable caching makes rebuilds faster.
  • The same file gives the same image, which matters for signing, attestations (#55) and the pinned config digest.
  • It catches a whole class of silent bugs before new features add more map-driven output.

How

Where things are
File What it does
pkg/agentkit2llb/agent/convert.go Agentkit2LLB() returns the build state and image settings.
pkg/agentkit2llb/agent/image.go NewImageConfig() builds the labels map and env list.
pkg/agentkit/abi/render.go Render() writes /agent/agent.yaml. copyMap (around line 246) copies brokered tool parameters, which are nested maps.
pkg/agentkit/effective/agent.go Turns the config into the build-ready agent, the input to all of the above.
dalec determinism_test.go The helper to copy: requireDeterministicLLB.
Steps
  1. Write a reusable helper, for example requireDeterministic(t, build func() []byte).
    • It calls build 25 times and requires every result to equal the first.
    • A single repeat would miss random ordering about half the time when a map has only two keys. Running many times makes a miss very unlikely, and each run is cheap.
    • Put it where tests in other packages can use it, for example a small internal/testutil package.
  2. For build steps, rebuild the state from scratch on every run, call Marshal(ctx), and compare only .Def. Metadata contains per-build noise such as progress-group IDs. Dalec's test explains why.
  3. Use a fixture with lots of map entries, so random order is very likely to show:
    • at least 12 metadata.labels;
    • several tools with env lists and headers;
    • a brokered tool with nested parameters;
    • context providers;
    • several env entries.
  4. Add the three checks: the build definition, the image settings marshaled to JSON, and the abi.Render output.
  5. Fix any differences by sorting keys before looping. Add a short comment wherever ordering matters.
  6. Point future work at the helper. Leave a comment on #54, #55 and #57 saying their new output should be added to these checks.
Tests

The new tests are the deliverable. Run them several times so a flaky pass is unlikely:

go test ./pkg/... -run Determin -count=5
go test ./...
make lint

Done when

  • The checks cover the build definition, the image settings and the /agent/agent.yaml bytes, using a map-heavy fixture.
  • They pass reliably, and any differences they found are fixed.
  • The helper is easy for #54, #55 and #57 to reuse.
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.