mirror of
https://github.com/max-sixty/worktrunk.git
synced 2026-09-14 20:00:38 +08:00
aa9d8c43df
Add a `remote_repo` variable that returns the repo name from the remote URL. Unlike `repo`, it stays consistent even if the clone was renamed. Feel free to reject, or suggest other names for the variable. But this change would improve my workflow. I hope you don't mind my submitting a PR before opening an issue. Thanks for an amazing developer tool! AI Disclosure 🤖: I used Claude Code to generate the changes, but reviewed every line and made adjustments. --------- Co-authored-by: worktrunk-bot <254187624+worktrunk-bot@users.noreply.github.com>
184 lines
4.3 KiB
Rust
184 lines
4.3 KiB
Rust
//! Integration tests for `wt step eval`
|
|
|
|
use crate::common::{TestRepo, make_snapshot_cmd, make_snapshot_cmd_with_global_flags, repo};
|
|
use insta_cmd::assert_cmd_snapshot;
|
|
use rstest::rstest;
|
|
|
|
#[rstest]
|
|
fn test_eval_branch(repo: TestRepo) {
|
|
assert_cmd_snapshot!(make_snapshot_cmd(
|
|
&repo,
|
|
"step",
|
|
&["eval", "{{ branch }}"],
|
|
None,
|
|
));
|
|
}
|
|
|
|
#[rstest]
|
|
fn test_eval_hash_port(repo: TestRepo) {
|
|
assert_cmd_snapshot!(make_snapshot_cmd(
|
|
&repo,
|
|
"step",
|
|
&["eval", "{{ branch | hash_port }}"],
|
|
None,
|
|
));
|
|
}
|
|
|
|
#[rstest]
|
|
fn test_eval_multiple_values(repo: TestRepo) {
|
|
assert_cmd_snapshot!(make_snapshot_cmd(
|
|
&repo,
|
|
"step",
|
|
&[
|
|
"eval",
|
|
"{{ branch | hash_port }},{{ (\"supabase-api-\" ~ branch) | hash_port }}"
|
|
],
|
|
None,
|
|
));
|
|
}
|
|
|
|
#[rstest]
|
|
fn test_eval_sanitize_db(repo: TestRepo) {
|
|
assert_cmd_snapshot!(make_snapshot_cmd(
|
|
&repo,
|
|
"step",
|
|
&["eval", "{{ branch | sanitize_db }}"],
|
|
None,
|
|
));
|
|
}
|
|
|
|
#[rstest]
|
|
fn test_eval_template_error(repo: TestRepo) {
|
|
assert_cmd_snapshot!(make_snapshot_cmd(
|
|
&repo,
|
|
"step",
|
|
&["eval", "{{ undefined_var }}"],
|
|
None,
|
|
));
|
|
}
|
|
|
|
#[rstest]
|
|
fn test_eval_verbose(repo: TestRepo) {
|
|
assert_cmd_snapshot!(make_snapshot_cmd_with_global_flags(
|
|
&repo,
|
|
"step",
|
|
&["eval", "{{ branch | hash_port }}"],
|
|
None,
|
|
&["--verbose"],
|
|
));
|
|
}
|
|
|
|
#[rstest]
|
|
fn test_eval_format_json(repo: TestRepo) {
|
|
assert_cmd_snapshot!(make_snapshot_cmd(
|
|
&repo,
|
|
"step",
|
|
&["eval", "--format=json", "{{ branch | hash_port }}"],
|
|
None,
|
|
));
|
|
}
|
|
|
|
/// `--format=json` and `-v` compose: JSON to stdout, the human expansion view
|
|
/// to stderr.
|
|
#[rstest]
|
|
fn test_eval_format_json_verbose(repo: TestRepo) {
|
|
assert_cmd_snapshot!(make_snapshot_cmd_with_global_flags(
|
|
&repo,
|
|
"step",
|
|
&["eval", "--format=json", "{{ branch | hash_port }}"],
|
|
None,
|
|
&["--verbose"],
|
|
));
|
|
}
|
|
|
|
#[rstest]
|
|
fn test_eval_owner(repo: TestRepo) {
|
|
repo.run_git(&[
|
|
"remote",
|
|
"set-url",
|
|
"origin",
|
|
"git@github.com:max-sixty/worktrunk.git",
|
|
]);
|
|
|
|
let output = repo
|
|
.wt_command()
|
|
.args(["step", "eval", "{{ owner }}/{{ repo }}"])
|
|
.output()
|
|
.expect("Failed to run wt step eval");
|
|
|
|
assert!(
|
|
output.status.success(),
|
|
"wt step eval should succeed, stderr: {}",
|
|
String::from_utf8_lossy(&output.stderr)
|
|
);
|
|
assert_eq!(
|
|
String::from_utf8_lossy(&output.stdout).trim(),
|
|
"max-sixty/repo"
|
|
);
|
|
}
|
|
|
|
#[rstest]
|
|
fn test_eval_remote_repo(repo: TestRepo) {
|
|
repo.run_git(&[
|
|
"remote",
|
|
"set-url",
|
|
"origin",
|
|
"git@github.com:company-org/project.git",
|
|
]);
|
|
|
|
let output = repo
|
|
.wt_command()
|
|
.args(["step", "eval", "{{ remote_repo }}/{{ repo }}"])
|
|
.output()
|
|
.expect("Failed to run wt step eval");
|
|
|
|
assert!(
|
|
output.status.success(),
|
|
"wt step eval should succeed, stderr: {}",
|
|
String::from_utf8_lossy(&output.stderr)
|
|
);
|
|
assert_eq!(
|
|
String::from_utf8_lossy(&output.stdout).trim(),
|
|
"project/repo"
|
|
);
|
|
}
|
|
|
|
#[rstest]
|
|
fn test_eval_conditional(repo: TestRepo) {
|
|
assert_cmd_snapshot!(make_snapshot_cmd(
|
|
&repo,
|
|
"step",
|
|
&[
|
|
"eval",
|
|
"{% if branch == 'main' %}production{% else %}development{% endif %}"
|
|
],
|
|
None,
|
|
));
|
|
}
|
|
|
|
/// `{{ commit }}` resolves to the running worktree's HEAD SHA on the on-branch
|
|
/// hot path. `build_hook_context` resolves it via `git rev-parse <branch>`
|
|
/// (always fresh from the ref store), so the value tracks any HEAD movement
|
|
/// during the command.
|
|
#[rstest]
|
|
fn test_eval_commit_matches_head_sha(repo: TestRepo) {
|
|
let expected = repo.git_output(&["rev-parse", "HEAD"]);
|
|
|
|
let output = repo
|
|
.wt_command()
|
|
.args(["step", "eval", "{{ commit }}"])
|
|
.output()
|
|
.expect("run wt step eval");
|
|
|
|
assert!(
|
|
output.status.success(),
|
|
"wt step eval failed: stderr={}",
|
|
String::from_utf8_lossy(&output.stderr),
|
|
);
|
|
assert_eq!(
|
|
String::from_utf8_lossy(&output.stdout).trim(),
|
|
expected,
|
|
"eval commit should match HEAD SHA"
|
|
);
|
|
}
|