Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .dagger/modules/dagger-pytest-otel/dagger-module.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name = "dagger-pytest-otel"
engineVersion = "v1.0.0-beta.15"
engineVersion = "v1.0.0-beta.22"

[runtime]
source = "dang"
Expand Down
2 changes: 1 addition & 1 deletion .dagger/modules/e2e/dagger-module.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name = "e2e"
engineVersion = "v1.0.0-beta.15"
engineVersion = "v1.0.0-beta.22"

[runtime]
source = "dang"
Expand Down
598 changes: 494 additions & 104 deletions .dagger/modules/e2e/main.dang

Large diffs are not rendered by default.

18 changes: 14 additions & 4 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,24 @@ One repository, one module per directory:
- `pyproject/` — the shared library. It never gets `@check` functions.
- `ruff/`, `pytest/`, `uv/`, `mypy/`, `ty/` — tool modules, each with its own
checks. `ruff/` never runs through uv; it is a standalone binary. Each one's
`projects` is a Dagger collection keyed by project root: checks live on the
item type, and the collection's batch functions run them over a selection.
`projects` is a Dagger collection keyed by project root, and checks live on
item types only: collection-level functions are plain helpers, never checks
or generators. There is no `.batch` namespace. pytest's leaves are
top-level tests (project > test file > test); every test check of a project
takes the engine-filtered `tests` collection as its `selection` and shares
one pytest command, whose report `pytest/helpers/pytest-report` indexes into
one result per check. Keep that command byte-identical for every check of a
project: build it only from the sorted selection, never from the check's
own name.
- `.dagger/modules/e2e` — one end-to-end suite covering every module.
- `testdata/` — fixture projects shared by the suite. Several fail on purpose.

The design this implements is `hack/designs/python-modules-design.html`.

To run the tests: `dagger check -m .dagger/modules/e2e`. Collections need
engine v1.0.0-beta.15 or later; until it is released, use a dev engine.
To run the tests: `dagger check --e-2-e`. The modules need engine
v1.0.0-beta.22 or later, for selected collection arguments on checks. Direct
Dang calls do not apply the engine's filtered collection view, so selection
and per-test attribution are tested through the CLI, by the suite's
`selected-*` checks.

When changing a module, always make sure the tests are up to date.
195 changes: 151 additions & 44 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion mypy/dagger-module.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name = "mypy"
engineVersion = "v1.0.0-beta.15"
engineVersion = "v1.0.0-beta.22"

[runtime]
source = "dang"
Expand Down
7 changes: 5 additions & 2 deletions mypy/main.dang
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,12 @@ type MypyProjects @collection {
}

"""
Type check the selected projects with mypy.
Type check the selected projects with mypy, each with its own command.

A plain function rather than a check, so that `dagger check` does not run
the same work twice: each project's own `typeCheck` is its check.
"""
typeCheck(ws: Workspace!): Void @check {
typeCheck(ws: Workspace!): Void {
# A selection over a list evaluates its elements concurrently, so every
# project is checked in parallel and every failure is reported.
let failures = paths.map { p => project(p) }.{{path, failure: typeCheckFailure(ws)}}
Expand Down
2 changes: 1 addition & 1 deletion pyproject/dagger-module.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name = "pyproject"
engineVersion = "v1.0.0-beta.15"
engineVersion = "v1.0.0-beta.22"

[runtime]
source = "dang"
124 changes: 109 additions & 15 deletions pyproject/main.dang
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,21 @@ type Pyproject {
)
}

"""
The lines matching `pattern` in the files, among those the projects in
`roots` own, that match the ripgrep `globs`. One search covers every
project, as for `ownedFiles`, so this runs no container. Paths are
workspace-root-relative; the order is the search's own, so a caller that
needs one sorts.
"""
ownedMatches(ws: Workspace!, globs: [String!]!, pattern: String!): [PythonMatch!]! {
let candidates = roots(ws)
let all = ownershipRoots(ws, candidates)
at(searchBase(ws, candidates)).searchMatches(ws, globs, pattern).filter { found =>
candidates.contains(ownerOf(all, parentPath(found.path)))
}
}

"""
The directory one search has to cover: the enclosing project when the cwd is
inside one, since its files outside the cwd are its own too, else the cwd.
Expand Down Expand Up @@ -723,6 +738,40 @@ type PythonProject {
.uniq
}

"""
The lines matching `pattern` in the files at or below this project root that
match the ripgrep `globs`, from one search with `exclude` pruned. Nested
projects' files included; paths are workspace-root-relative.
"""
searchMatches(ws: Workspace!, globs: [String!]!, pattern: String!): [PythonMatch!]! {
ws
.search(paths: ["/" + subpath("")], globs: globs + searchExcludes, pattern: pattern)
.{{filePath, matchedLines}}
.map { found =>
PythonMatch(
path: found.filePath.trimPrefix("/").trimPrefix("./"),
line: found.matchedLines.trimSuffix("\n").trimSuffix("\r"),
)
}
}

"""
The lines matching `pattern` in the files matching the ripgrep `globs` that
belong to this project rather than to a project nested inside it, with
project-relative paths. The order is the search's own.
"""
ownMatches(ws: Workspace!, globs: [String!]!, pattern: String!): [PythonMatch!]! {
let nested = nestedProjects(ws)
searchMatches(ws, globs, pattern)
.map { found =>
PythonMatch(
path: if (path == ".") { found.path } else { found.path.trimPrefix(path + "/") },
line: found.line,
)
}
.reject { found => nested.any { dir => found.path.hasPrefix(dir + "/") } }
}

"""
`exclude` as ripgrep globs. A "dir/**" pattern also names the directory
itself, so ripgrep skips it instead of walking every file inside.
Expand Down Expand Up @@ -968,6 +1017,49 @@ type PythonProject {
what: String!,
nesting: Boolean! = false,
): Container! {
let done = nestable(ctr, nesting).withExec(args, expect: ReturnType.ANY, daggerInDaggerNewSession: nesting)
let code = done.exitCode
if (code == 0) {
done
} else {
let tail = (done.stdout + "\n" + done.stderr)
.split("\n")
.reject { line => line.trimSpace == "" }
.takeLast(12)
.map { line => " " + line }
.join("\n")
let detail = if (tail == "") { "" } else { ":\n" + tail }
raise what + " failed (" + args.join(" ") + ", exit code " + toString(code) + ")" + detail
}
}

"""
Run one step whatever its exit code, with its stdout and stderr redirected
to the named files, for a caller that reads a machine report and the exit
code rather than having the step raise.

A tool whose results are shared between several checks runs here: a raise
would fail every one of them with the same message, while the report can
say which of them actually failed.
"""
attempt(
ctr: Container!,
args: [String!]!,
stdout: String!,
stderr: String!,
nesting: Boolean! = false,
): Container! {
nestable(ctr, nesting).withExec(
args,
expect: ReturnType.ANY,
redirectStdout: stdout,
redirectStderr: stderr,
daggerInDaggerNewSession: nesting,
)
}

# A container ready to run a step that may talk to a nested Dagger engine.
let nestable(ctr: Container!, nesting: Boolean!): Container! {
# A nested session finds its workspace root by walking up to a .git
# directory, and the container mirrors the workspace under /ws, so without
# a marker there the session gets an empty workspace and every
Expand All @@ -982,27 +1074,13 @@ type PythonProject {
# one at /dev/.dagger/dagger; name it, because the SDK otherwise downloads
# the release its own client was generated against, over the network and
# against an engine of whatever version the user is on.
let nested = if (nesting) {
if (nesting) {
ctr
.withDirectory(mountRoot + "/.git", directory)
.withEnvVariable("_EXPERIMENTAL_DAGGER_CLI_BIN", "/dev/.dagger/dagger")
} else {
ctr
}
let done = nested.withExec(args, expect: ReturnType.ANY, daggerInDaggerNewSession: nesting)
let code = done.exitCode
if (code == 0) {
done
} else {
let tail = (done.stdout + "\n" + done.stderr)
.split("\n")
.reject { line => line.trimSpace == "" }
.takeLast(12)
.map { line => " " + line }
.join("\n")
let detail = if (tail == "") { "" } else { ":\n" + tail }
raise what + " failed (" + args.join(" ") + ", exit code " + toString(code) + ")" + detail
}
}

"""
Expand Down Expand Up @@ -1226,3 +1304,19 @@ type PythonProject {
}
}
}

"""
A line one workspace search matched.
"""
type PythonMatch {
"""
The file that holds the line: workspace-root-relative, or project-relative
from a project's own search.
"""
path: String!

"""
The matched line, without its line ending.
"""
line: String!
}
2 changes: 1 addition & 1 deletion pytest/dagger-module.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name = "pytest"
engineVersion = "v1.0.0-beta.15"
engineVersion = "v1.0.0-beta.22"

[runtime]
source = "dang"
Expand Down
Loading