---
id: w1/m18/t009
title: Test coverage for rootDir behavior
worker: worker1
status: done
estimate: 45m
depends_on: [w1/m18/t007]
---

## Objective

Add meaningful tests asserting real behavior and failure modes for the subdir build-context construction, the webhook path filter, and the API surface field — not tautological or snapshot-everything tests.

## Context

- `lego/operator/internal/build/build_test.go` already has a pattern for asserting the BuildKit `context=` string.
- `lego/backend/internal/apps` has existing webhook tests (`webhook_test.go` if present, else co-located `_test.go` files) covering `repoMatches`/`branchMatches`.

## Steps

1. Unit tests for `gitContext`/`build.Options` subdir suffix: empty `RootDir` unchanged, non-empty `RootDir` appends `:<subdir>`, edge cases (leading/trailing slash, empty ref + rootDir combo).
2. Unit tests for the webhook path filter: empty `rootDir` always matches; a change strictly outside `rootDir` doesn't match; a change under `rootDir` matches; prefix-vs-substring edge case (`"foo"` must not match `"foobar/x"`).
3. A round-trip test (or extend an existing create/update test) confirming `rootDir` set via one adapter is readable via the others, if such a cross-adapter test pattern already exists in the codebase — otherwise per-adapter unit tests are sufficient.

## Files

- `lego/operator/internal/build/build_test.go`
- `lego/backend/internal/apps/webhook_test.go` (or equivalent)
- `lego/backend/internal/apps/service_test.go` / adapter test files as applicable

## Acceptance criteria

- [x] Tests assert real failure modes (wrong subdir not matched, substring-not-prefix bug caught), not just happy path
- [x] `go test ./...` green in both `lego/operator/` and `lego/backend/`

## Out of scope

- End-to-end/live verification against a real monorepo — covered by the milestone's Definition of Done at Closeout.
