Skip to content

Worktrunk is a CLI for Git worktree management, designed for parallel AI agent workflows

test(doc-templates): replace rotted doc line-number citations and stale template examples (#4012)

Worktrunk Bot8db40d2a8007
diff --git a/tests/integration_tests/doc_templates.rs b/tests/integration_tests/doc_templates.rs
index a112377d6..3e020d8c6 100644
--- a/tests/integration_tests/doc_templates.rs
+++ b/tests/integration_tests/doc_templates.rs
@@ -35,7 +35,7 @@ fn test_doc_basic_variables(repo: TestRepo) {
let mut vars = HashMap::new();
vars.insert("repo", "myproject");
vars.insert("branch", "feature/auth");
- vars.insert("worktree", "/home/user/myproject.feature-auth");
+ vars.insert("worktree_path", "/home/user/myproject.feature-auth");
vars.insert("default_branch", "main");
// Each variable substitutes correctly
@@ -63,7 +63,7 @@ fn test_doc_basic_variables(repo: TestRepo) {
);
assert_eq!(
expand_template(
- "{{ worktree }}",
+ "{{ worktree_path }}",
&vars,
ShellEscapeMode::Literal,
&repository,
@@ -360,7 +360,8 @@ fn test_doc_hash_port_concatenation_precedence(repo: TestRepo) {
#[rstest]
fn test_doc_hash_port_repo_branch_concatenation(repo: TestRepo) {
- // From docs/src/content/docs/hook.md line 176:
+ // From docs/src/content/docs/hook.md, "Worktrunk filters"
+ // ("Hash any string, including concatenations"):
// dev = "npm run dev --port {{ (repo ~ '-' ~ branch) | hash_port }}"
let repository = Repository::at(repo.root_path()).unwrap();
@@ -392,19 +393,21 @@ fn test_doc_hash_port_repo_branch_concatenation(repo: TestRepo) {
// =============================================================================
#[rstest]
-fn test_doc_example_docker_postgres(repo: TestRepo) {
- // From docs/src/content/docs/tips-patterns.md lines 75-84:
- // docker run ... -p {{ ('db-' ~ branch) | hash_port }}:5432
+fn test_doc_example_database_vars(repo: TestRepo) {
+ // From docs/src/content/docs/tips-patterns.md, "Database per worktree" —
+ // the `set-vars` step that derives the container name and port:
+ // wt config state vars set \
+ // container='{{ repo }}-{{ branch | sanitize }}-postgres' \
+ // port='{{ ('db-' ~ branch) | hash_port }}'
let repository = Repository::at(repo.root_path()).unwrap();
let mut vars = HashMap::new();
vars.insert("repo", "myproject");
vars.insert("branch", "feature-auth");
- let template = r#"docker run -d --rm \
- --name {{ repo }}-{{ branch | sanitize }}-postgres \
- -p {{ ('db-' ~ branch) | hash_port }}:5432 \
- postgres:16"#;
+ let template = r#"wt config state vars set \
+ container='{{ repo }}-{{ branch | sanitize }}-postgres' \
+ port='{{ ('db-' ~ branch) | hash_port }}'"#;
let result = expand_template(
template,
@@ -417,29 +420,29 @@ fn test_doc_example_docker_postgres(repo: TestRepo) {
// Check the container name uses sanitized branch
assert!(
- result.contains("--name myproject-feature-auth-postgres"),
- "Container name should use sanitized branch"
+ result.contains("container='myproject-feature-auth-postgres'"),
+ "Container name should use sanitized branch, got: {result}"
);
// Check the port is a hash of "db-feature-auth"
let expected_port = hash_port("db-feature-auth");
assert!(
- result.contains(&format!("-p {expected_port}:5432")),
- "Port should be hash of 'db-feature-auth', expected {expected_port}"
+ result.contains(&format!("port='{expected_port}'")),
+ "Port should be hash of 'db-feature-auth', expected {expected_port}, got: {result}"
);
}
#[rstest]
fn test_doc_example_database_url(repo: TestRepo) {
- // From docs/src/content/docs/tips-patterns.md lines 96-101:
- // DATABASE_URL=postgres://postgres:dev@localhost:{{ ('db-' ~ branch) | hash_port }}/{{ repo }}
+ // From docs/src/content/docs/tips-patterns.md, "Database per worktree" —
+ // the `db_url` var the `set-vars` step stores:
+ // db_url='postgres://postgres:dev@localhost:{{ ('db-' ~ branch) | hash_port }}/{{ branch | sanitize_db }}'
let repository = Repository::at(repo.root_path()).unwrap();
let mut vars = HashMap::new();
- vars.insert("repo", "myproject");
vars.insert("branch", "feature");
- let template = "DATABASE_URL=postgres://postgres:dev@localhost:{{ ('db-' ~ branch) | hash_port }}/{{ repo }}";
+ let template = "postgres://postgres:dev@localhost:{{ ('db-' ~ branch) | hash_port }}/{{ branch | sanitize_db }}";
let result = expand_template(
template,
@@ -450,16 +453,19 @@ fn test_doc_example_database_url(repo: TestRepo) {
)
.unwrap();
+ // `sanitize_db` appends a short hash suffix, so match the stable prefix.
let expected_port = hash_port("db-feature");
- assert_eq!(
- result,
- format!("DATABASE_URL=postgres://postgres:dev@localhost:{expected_port}/myproject")
+ assert!(
+ result.starts_with(&format!(
+ "postgres://postgres:dev@localhost:{expected_port}/feature_"
+ )),
+ "db_url should carry the 'db-feature' port and the sanitized database name, got: {result}"
);
}
#[rstest]
fn test_doc_example_dev_server(repo: TestRepo) {
- // From docs/src/content/docs/hook.md lines 168-170:
+ // From docs/src/content/docs/hook.md, "Worktrunk filters":
// dev = "npm run dev -- --host {{ branch }}.localhost --port {{ branch | hash_port }}"
let repository = Repository::at(repo.root_path()).unwrap();
@@ -486,15 +492,15 @@ fn test_doc_example_dev_server(repo: TestRepo) {
#[rstest]
fn test_doc_example_worktree_path_sanitize(repo: TestRepo) {
- // From docs/src/content/docs/tips-patterns.md line 217:
- // worktree-path = "{{ branch | sanitize }}"
+ // From docs/src/content/docs/tips-patterns.md, "Bare repository layout":
+ // worktree-path = "{{ repo_path }}/../{{ branch | sanitize }}"
let repository = Repository::at(repo.root_path()).unwrap();
let mut vars = HashMap::new();
vars.insert("branch", "feature/user/auth");
- vars.insert("main_worktree", "/home/user/project");
+ vars.insert("repo_path", "/home/user/myproject/.git");
- let template = "{{ main_worktree }}.{{ branch | sanitize }}";
+ let template = "{{ repo_path }}/../{{ branch | sanitize }}";
let result = expand_template(
template,
@@ -504,7 +510,7 @@ fn test_doc_example_worktree_path_sanitize(repo: TestRepo) {
"test",
)
.unwrap();
- assert_eq!(result, "/home/user/project.feature-user-auth");
+ assert_eq!(result, "/home/user/myproject/.git/../feature-user-auth");
}
// =============================================================================