mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-12-05 08:05:42 +00:00
* feat: run a workspace's post-fork script in each new fork Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: run a post-fork script as the forker and accept one not yet synced Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: run the post-fork script as g/post_fork_script, not the forker Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * feat: count post-fork script configuration and runs Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * docs: say the post-fork script runs as its group Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chore: update ee-repo-ref to 637c53ae3771c8292f29d49e91b4c61bd3a0b0f3 This commit updates the EE repository reference after PR #1048 was merged in windmill-ee-private. Previous ee-repo-ref: 19a843a872e4ffb2abed9abb92109d5ebf271683 New ee-repo-ref: 637c53ae3771c8292f29d49e91b4c61bd3a0b0f3 Automated by sync-ee-ref workflow. * feat: put the post-fork script at the bottom of data tables, collapsed when unset Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: keep the post-fork script description inside its collapsed card Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * fix: complete a background fork only after its post-fork script launch is recorded Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: windmill-internal-app[bot] <windmill-internal-app[bot]@users.noreply.github.com>
94 lines
3.1 KiB
Rust
94 lines
3.1 KiB
Rust
use serde_json::json;
|
|
use sqlx::{Pool, Postgres};
|
|
|
|
use windmill_test_utils::*;
|
|
|
|
/// A parent's post-fork script starts in each new fork as `g/post_fork_script`, not as whoever
|
|
/// forks, so editing the script never runs code as a forking admin; one the fork lacks is
|
|
/// reported, not run, and the fork stands either way.
|
|
#[sqlx::test(migrations = "../migrations", fixtures("base"))]
|
|
async fn test_post_fork_script_runs_as_its_group(db: Pool<Postgres>) -> anyhow::Result<()> {
|
|
initialize_tracing().await;
|
|
let server = ApiServer::start(db.clone()).await?;
|
|
let base_url = format!(
|
|
"http://localhost:{}/api/w/test-workspace/workspaces",
|
|
server.addr.port()
|
|
);
|
|
let client = reqwest::Client::new();
|
|
|
|
sqlx::query(
|
|
"INSERT INTO script (workspace_id, hash, path, content, language, kind, created_by, schema,
|
|
summary, description, lock, extra_perms)
|
|
VALUES ('test-workspace', 1, 'u/test-user/setup', 'echo hi', 'bash', 'script', 'test-user',
|
|
'{}', '', '', '', '{}')",
|
|
)
|
|
.execute(&db)
|
|
.await?;
|
|
|
|
let set_hook = |path: &'static str| {
|
|
client
|
|
.post(format!("{base_url}/edit_post_fork_script"))
|
|
.header("Authorization", "Bearer SECRET_TOKEN")
|
|
.json(&json!({ "path": path }))
|
|
.send()
|
|
};
|
|
let fork = |id: &'static str| {
|
|
client
|
|
.post(format!("{base_url}/create_fork"))
|
|
.header("Authorization", "Bearer SECRET_TOKEN_2")
|
|
.json(&json!({ "id": id, "name": id }))
|
|
.send()
|
|
};
|
|
|
|
let resp = set_hook("script/u/test-user/setup").await?;
|
|
assert!(
|
|
resp.status().is_success(),
|
|
"setting: {}",
|
|
resp.text().await?
|
|
);
|
|
let resp = fork("wm-fork-ran").await?;
|
|
assert!(resp.status().is_success(), "fork: {}", resp.text().await?);
|
|
|
|
let jobs: Vec<(String, String, Option<bool>, Vec<String>)> = sqlx::query_as(
|
|
"SELECT j.runnable_path, j.permissioned_as, p.is_admin, j.labels
|
|
FROM v2_job j LEFT JOIN job_perms p ON p.job_id = j.id
|
|
WHERE j.workspace_id = 'wm-fork-ran'",
|
|
)
|
|
.fetch_all(&db)
|
|
.await?;
|
|
assert_eq!(
|
|
jobs,
|
|
vec![(
|
|
"u/test-user/setup".to_string(),
|
|
"g/post_fork_script".to_string(),
|
|
Some(false),
|
|
vec!["post_fork_script".to_string()],
|
|
)]
|
|
);
|
|
|
|
// CE counts every live workspace against a cap of two.
|
|
sqlx::query("UPDATE workspace SET deleted = true WHERE id = 'wm-fork-ran'")
|
|
.execute(&db)
|
|
.await?;
|
|
let resp = set_hook("flow/u/test-user/missing").await?;
|
|
assert!(
|
|
resp.status().is_success(),
|
|
"setting: {}",
|
|
resp.text().await?
|
|
);
|
|
let resp = fork("wm-fork-missing").await?;
|
|
let text = resp.text().await?;
|
|
assert!(
|
|
text.contains("Created forked workspace wm-fork-missing")
|
|
&& text.contains("is not in the fork"),
|
|
"{text}"
|
|
);
|
|
let jobs: i64 =
|
|
sqlx::query_scalar("SELECT count(*) FROM v2_job WHERE workspace_id = 'wm-fork-missing'")
|
|
.fetch_one(&db)
|
|
.await?;
|
|
assert_eq!(jobs, 0);
|
|
|
|
Ok(())
|
|
}
|