Skip to content

feat(cli): implement test subcommand for autopkgtests - #26

Open
mikonse wants to merge 1 commit into
mainfrom
milo/debmagic-test-subcommand
Open

feat(cli): implement test subcommand for autopkgtests#26
mikonse wants to merge 1 commit into
mainfrom
milo/debmagic-test-subcommand

Conversation

@mikonse

@mikonse mikonse commented Aug 11, 2026

Copy link
Copy Markdown
Member

No description provided.

@mikonse
mikonse requested a review from TheJJ August 11, 2026 21:28

@TheJJ TheJJ left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wooh! well done :)

some ideas for improvements:

  • why is test part of build/ and test_intent is not? maybe have a test/ subdirectory for both.
  • i think we should factor out a containerconfig, and the container drivers to a container/ module outside of build, they are used by build and test (and soon lint, maybe more). the buildconfig and testconfig can then use the containerconfig.

Comment thread docs/usage/test.md

## TL;DR

- Entry point: `debmagic test` — runs tests from `debian/tests/control` against the `.debs` of a prior `debmagic build`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.debs is not right, just leave it out and say need prior build

Comment thread docs/usage/test.md
| `--source-dir <dir>` | Directory containing the `debian/` package directory |
| `--allow-host-test` | Allow the bare driver, which runs autopkgtest as root on the host |

[`debmagic shell`](#inspecting-a-failed-test-run) — attach an interactive shell to a test environment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how do we select build/test environment?

Comment thread docs/usage/test.md
| `1` | Test failure, testbed error, or other autopkgtest error |
| `2` | Strict-only failure: skipped tests or no tests declared under `--strict` |

autopkgtest skips tests whose `Restrictions:` the `null` backend cannot satisfy (e.g. `isolation-container`, `isolation-machine`). Skips are reported loudly; use `--strict` to escalate them to exit code 2.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can pass capabilities to the null driver which it then pretends to have. and we are in a container (or even lxd vm), so we can give those caps to the null driver.

.map_err(|e| std::io::Error::new(std::io::ErrorKind::InvalidInput, e))?;

self.exec_in_container(cmd, Some(&container_path), requires_root, env_add)
self.exec_in_container_exit_status(cmd, Some(&container_path), requires_root, env_add)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

naming it exit_status is weird. why not just exec_in_container

}

fn run_command_env(
fn run_command_exit_status(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why exit_status, it's not that special, run_command alone would be a better name

let base_config = prior_build
.as_ref()
.map(|metadata| metadata.config.clone())
.unwrap_or_else(|| BuildConfig {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems wrong here, what do we need to construct a whole BuildConfig for?

purpose: EnvironmentPurpose::Test,
});

let test_config = BuildConfig {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

all signing etc is unneeded for testing. this looks like we need a separate containerconfig, which is then used by buildconfig and testconfig


let apt_env = [("DEBIAN_FRONTEND", "noninteractive")];
test_run.driver.run_command_env(
&["apt-get", "update"],

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not something that should be involed here. if needed, a "initial package list update" flag should be passed to the container driver.

changes_filename,
&format!("{source_tree_name}/"),
"--",
"null",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here we can pass more capabilities to null, e.g. isolation container/vm (if environment is vm)

let outcome = map_autopkgtest_exit(exit_code, intent.strict);

if outcome == TestOutcome::Failed && stdout().is_terminal() {
eprintln!("Tests failed (autopkgtest exit code {exit_code}). Dropping into shell...");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

always a shell is probably annoying, if one iterates on a fix.

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.

2 participants