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
18 changes: 15 additions & 3 deletions app/src/domain/build_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,27 @@ pub fn stored_config(build: &Build) -> Result<Option<Config>, ConfigInvalid> {
}
}

/// The warning for a build whose visualci.yml asks for a gallery the project has turned off (or never turned on).
pub const GALLERY_OFF: &str = "visualci.yml's gallery names screenshots to publish, but this project's gallery is off, \
so none of them is public. Turn the gallery on in the project's settings (gallery_enabled) to publish them.";

/// The warnings to show with a build: the ones stored when it was created and processed, and, when its stored
/// `visualci.yml` no longer validates and the build didn't already fail for it, that problem first. Used by every view
/// of a build (the API and MCP answers, the build's page, its check), so a build compared before its file stopped
/// validating says so wherever it's read.
/// validating says so wherever it's read. A file whose `gallery` asks to publish screenshots while the project's gallery
/// is off says that too, since nothing it names is public until someone turns the gallery on.
#[must_use]
pub fn warnings_of(build: &Build) -> Vec<String> {
pub fn warnings_of(project: &Project, build: &Build) -> Vec<String> {
let mut out: Vec<String> = serde_json::from_value(build.warnings.clone()).unwrap_or_default();
let config = stored_config(build);
if !project.gallery_enabled
&& let Ok(Some(c)) = &config
&& c.gallery.as_ref().is_some_and(|g| !g.groups.is_empty())
{
out.push(GALLERY_OFF.to_string());
}
if build.error_code.as_deref() != Some(CONFIG_INVALID)
&& let Err(e) = stored_config(build)
&& let Err(e) = config
{
out.insert(
0,
Expand Down
7 changes: 5 additions & 2 deletions app/src/domain/projects.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ pub fn is_unique_violation(e: &laravel::Error) -> bool {
text.contains("23505") || text.contains("duplicate key value violates unique constraint")
}

/// Make a project in an organization, with the organization's settings for new projects.
/// Make a project in an organization, with the organization's settings for new projects and its gallery off. Every
/// way to make one (the web app, MCP, a GitHub App import) comes through here, so they share one set of defaults.
///
/// # Errors
/// `Ok(Err(_))` for a slug that isn't valid or is taken; `Err` on a database error.
Expand All @@ -216,7 +217,8 @@ pub async fn create(organization_id: i64, slug: &str, name: &str) -> laravel::Re
return Ok(Err(Refused::Taken));
}
let name = name.trim();
// It starts with the organization's defaults for new projects
// It starts with the organization's defaults for new projects, and with its gallery off: nothing is public until
// someone turns the gallery on, whatever visualci.yml's `gallery` asks for (the build's warnings say so).
let org = crate::models::Organization::find_or_fail(organization_id).await?;
match laravel::model::create!(Project {
pid: laravel::str::uuid7(),
Expand All @@ -225,6 +227,7 @@ pub async fn create(organization_id: i64, slug: &str, name: &str) -> laravel::Re
name: name,
threshold: org.project_threshold,
comment_when_unchanged: org.project_comment_when_unchanged,
gallery_enabled: false,
})
.await
{
Expand Down
2 changes: 1 addition & 1 deletion app/src/forge/checks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ async fn own_check(build: &Build, project: &Project, org: &Organization) -> lara
{
summary.push_str(&format!("\n\n**Error:** {error}"));
}
for warning in build_settings::warnings_of(build) {
for warning in build_settings::warnings_of(project, build) {
summary.push_str(&format!("\n\n**Warning:** {warning}"));
}
if project.deleted_at.is_some() {
Expand Down
2 changes: 1 addition & 1 deletion app/src/http/api/builds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl BuildResponse {
stats: domain::stats(build),
error: build.error.clone(),
url: format!("{}/{}/{}/builds/{}", app_url(), organization.slug, project.slug, build.number),
warnings: crate::domain::build_settings::warnings_of(build),
warnings: crate::domain::build_settings::warnings_of(project, build),
reviewable: domain::reviewable(build),
blocked: None,
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/http/ui/builds.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ pub async fn show_build(auth: Auth<User>, Params((org, project, number)): Params
summary["base_build_number"] = json!(base_number);
summary["ci_mode"] = json!(BuildSettings::shown(project, &build).ci_mode());
summary["config"] = json!(build.config);
summary["warnings"] = json!(domain::build_settings::warnings_of(&build));
summary["warnings"] = json!(domain::build_settings::warnings_of(project, &build));
summary["error"] = json!(build.error);
// What changed, computed from the comparison.
summary["summary"] = json!(domain::summary::summary_line(&build).await?);
Expand Down
2 changes: 1 addition & 1 deletion app/src/mcp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1259,7 +1259,7 @@ impl VisualCi {
out["config"] = json!(build.config);
// What changed, computed from the comparison ("invoice: page 1 changed (2 regions); 3 added").
out["summary"] = json!(domain::summary::summary_line(&build).await.map_err(internal)?);
out["warnings"] = json!(domain::build_settings::warnings_of(&build));
out["warnings"] = json!(domain::build_settings::warnings_of(&project, &build));
out["ci_mode"] = json!(BuildSettings::shown(&project, &build).ci_mode());
if paged {
out["groups"] = json!(
Expand Down
27 changes: 27 additions & 0 deletions app/tests/gallery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,3 +273,30 @@ async fn cap_and_dropouts(app: Application) -> laravel::Result<()> {
assert_eq!(app.get("/status").await.json()["gallery_purges_failed"], 1);
Ok(())
}

/// Every way to make a project goes through one create path, which starts its gallery off: a visualci.yml that names a
/// gallery publishes nothing until someone turns the gallery on, and the build's warnings say why (case studies, 7).
#[laravel::test]
async fn a_new_project_publishes_nothing_until_its_gallery_is_turned_on(app: Application) -> laravel::Result<()> {
let mut w = world().await?;
let project = app::domain::projects::create(w.org.id, "fresh", "Fresh").await?.expect("a valid, free slug");
assert!(!project.gallery_enabled, "a new project's gallery starts off");
let (old, new) = (w.project.id, project.id);
db::query!("UPDATE project_tokens SET project_id = {new} WHERE project_id = {old}").update().await?;
w.project = project;

let b = w.build(&app, "A", "main", &[], &[("web/home", RED)]).await;
let base = format!("/g/{}/fresh", w.org.slug);
app.get(format!("{base}.json")).await.assert_status(404);
app.get(format!("{base}/web/home.png")).await.assert_status(404);
let project = Project::find_or_fail(new).await?;
let warnings = app::domain::build_settings::warnings_of(&project, &b);
assert_eq!(warnings, vec![app::domain::build_settings::GALLERY_OFF.to_string()]);

// Turned on, it publishes, and the warning goes.
let change = serde_json::from_value(json!({ "gallery_enabled": true })).expect("a settings change");
let project = app::domain::projects::change_settings(project, change).await?.expect("a valid change");
app.get(format!("{base}/web/home.png")).await.assert_ok();
assert!(app::domain::build_settings::warnings_of(&project, &b).is_empty());
Ok(())
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"result": {
"content": [
{
"text": "{\"project\":\"<org:1>-b/docs\",\"settings\":{\"ci_mode\":\"review\",\"comment_when_unchanged\":false,\"default_branch\":\"main\",\"dpi\":140,\"forge\":null,\"forge_app_installed\":false,\"forge_webhook_at\":null,\"gallery_enabled\":true,\"ignore_anti_aliasing\":false,\"ignore_rules\":[],\"name\":\"Docs\",\"notice\":null,\"open_source\":false,\"open_source_note\":null,\"open_source_pool\":false,\"open_source_withdrawn\":false,\"public\":false,\"renderer\":\"pdfbox\",\"repository_public\":false,\"repository_url\":null,\"slug\":\"docs\",\"threshold\":0.0,\"tokens_can_approve\":true}}",
"text": "{\"project\":\"<org:1>-b/docs\",\"settings\":{\"ci_mode\":\"review\",\"comment_when_unchanged\":false,\"default_branch\":\"main\",\"dpi\":140,\"forge\":null,\"forge_app_installed\":false,\"forge_webhook_at\":null,\"gallery_enabled\":false,\"ignore_anti_aliasing\":false,\"ignore_rules\":[],\"name\":\"Docs\",\"notice\":null,\"open_source\":false,\"open_source_note\":null,\"open_source_pool\":false,\"open_source_withdrawn\":false,\"public\":false,\"renderer\":\"pdfbox\",\"repository_public\":false,\"repository_url\":null,\"slug\":\"docs\",\"threshold\":0.0,\"tokens_can_approve\":true}}",
"type": "text"
}
],
Expand All @@ -22,7 +22,7 @@
"forge": null,
"forge_app_installed": false,
"forge_webhook_at": null,
"gallery_enabled": true,
"gallery_enabled": false,
"ignore_anti_aliasing": false,
"ignore_rules": [],
"name": "Docs",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
"result": {
"content": [
{
"text": "{\"gallery\":{\"enabled\":true,\"items\":[],\"manifest_url\":null},\"project\":\"<org:1>-b/docs\",\"repository_seen_in_ci\":null,\"settings\":{\"ci_mode\":\"review\",\"comment_when_unchanged\":false,\"default_branch\":\"main\",\"dpi\":150,\"forge\":null,\"forge_app_installed\":false,\"forge_webhook_at\":null,\"gallery_enabled\":true,\"ignore_anti_aliasing\":false,\"ignore_rules\":[{\"json_paths\":[\"$.generated_at\"],\"snapshots\":\"api/**\",\"text_patterns\":[\"\\\\d{4}-\\\\d{2}-\\\\d{2}\"]}],\"name\":\"Docs\",\"notice\":null,\"open_source\":false,\"open_source_note\":null,\"open_source_pool\":false,\"open_source_withdrawn\":false,\"public\":false,\"renderer\":\"pdfbox\",\"repository_public\":false,\"repository_url\":null,\"slug\":\"docs\",\"threshold\":0.0,\"tokens_can_approve\":true},\"tokens\":[{\"created_at\":\"<time:1>\",\"id\":3,\"last_used_at\":null,\"name\":\"CircleCI\",\"prefix\":\"<token:1>\"}],\"url\":\"https://app.visualci.test/<org:1>-b/docs\"}",
"text": "{\"gallery\":{\"enabled\":false,\"items\":[],\"manifest_url\":null},\"project\":\"<org:1>-b/docs\",\"repository_seen_in_ci\":null,\"settings\":{\"ci_mode\":\"review\",\"comment_when_unchanged\":false,\"default_branch\":\"main\",\"dpi\":150,\"forge\":null,\"forge_app_installed\":false,\"forge_webhook_at\":null,\"gallery_enabled\":false,\"ignore_anti_aliasing\":false,\"ignore_rules\":[{\"json_paths\":[\"$.generated_at\"],\"snapshots\":\"api/**\",\"text_patterns\":[\"\\\\d{4}-\\\\d{2}-\\\\d{2}\"]}],\"name\":\"Docs\",\"notice\":null,\"open_source\":false,\"open_source_note\":null,\"open_source_pool\":false,\"open_source_withdrawn\":false,\"public\":false,\"renderer\":\"pdfbox\",\"repository_public\":false,\"repository_url\":null,\"slug\":\"docs\",\"threshold\":0.0,\"tokens_can_approve\":true},\"tokens\":[{\"created_at\":\"<time:1>\",\"id\":3,\"last_used_at\":null,\"name\":\"CircleCI\",\"prefix\":\"<token:1>\"}],\"url\":\"https://app.visualci.test/<org:1>-b/docs\"}",
"type": "text"
}
],
"isError": false,
"structuredContent": {
"gallery": {
"enabled": true,
"enabled": false,
"items": [],
"manifest_url": null
},
Expand All @@ -26,7 +26,7 @@
"forge": null,
"forge_app_installed": false,
"forge_webhook_at": null,
"gallery_enabled": true,
"gallery_enabled": false,
"ignore_anti_aliasing": false,
"ignore_rules": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"result": {
"content": [
{
"text": "{\"settings\":{\"ci_mode\":\"review\",\"comment_when_unchanged\":false,\"default_branch\":\"main\",\"dpi\":150,\"forge\":null,\"forge_app_installed\":false,\"forge_webhook_at\":null,\"gallery_enabled\":true,\"ignore_anti_aliasing\":false,\"ignore_rules\":[{\"json_paths\":[\"$.generated_at\"],\"snapshots\":\"api/**\",\"text_patterns\":[\"\\\\d{4}-\\\\d{2}-\\\\d{2}\"]}],\"name\":\"Docs\",\"notice\":null,\"open_source\":false,\"open_source_note\":null,\"open_source_pool\":false,\"open_source_withdrawn\":false,\"public\":false,\"renderer\":\"pdfbox\",\"repository_public\":false,\"repository_url\":null,\"slug\":\"docs\",\"threshold\":0.0,\"tokens_can_approve\":true}}",
"text": "{\"settings\":{\"ci_mode\":\"review\",\"comment_when_unchanged\":false,\"default_branch\":\"main\",\"dpi\":150,\"forge\":null,\"forge_app_installed\":false,\"forge_webhook_at\":null,\"gallery_enabled\":false,\"ignore_anti_aliasing\":false,\"ignore_rules\":[{\"json_paths\":[\"$.generated_at\"],\"snapshots\":\"api/**\",\"text_patterns\":[\"\\\\d{4}-\\\\d{2}-\\\\d{2}\"]}],\"name\":\"Docs\",\"notice\":null,\"open_source\":false,\"open_source_note\":null,\"open_source_pool\":false,\"open_source_withdrawn\":false,\"public\":false,\"renderer\":\"pdfbox\",\"repository_public\":false,\"repository_url\":null,\"slug\":\"docs\",\"threshold\":0.0,\"tokens_can_approve\":true}}",
"type": "text"
}
],
Expand All @@ -31,7 +31,7 @@
"forge": null,
"forge_app_installed": false,
"forge_webhook_at": null,
"gallery_enabled": true,
"gallery_enabled": false,
"ignore_anti_aliasing": false,
"ignore_rules": [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"result": {
"content": [
{
"text": "{\"settings\":{\"ci_mode\":\"review\",\"comment_when_unchanged\":false,\"default_branch\":\"main\",\"dpi\":150,\"forge\":null,\"forge_app_installed\":false,\"forge_webhook_at\":null,\"gallery_enabled\":true,\"ignore_anti_aliasing\":false,\"ignore_rules\":[],\"name\":\"Docs\",\"notice\":null,\"open_source\":false,\"open_source_note\":null,\"open_source_pool\":false,\"open_source_withdrawn\":false,\"public\":false,\"renderer\":\"pdfbox\",\"repository_public\":false,\"repository_url\":null,\"slug\":\"docs\",\"threshold\":0.0,\"tokens_can_approve\":true}}",
"text": "{\"settings\":{\"ci_mode\":\"review\",\"comment_when_unchanged\":false,\"default_branch\":\"main\",\"dpi\":150,\"forge\":null,\"forge_app_installed\":false,\"forge_webhook_at\":null,\"gallery_enabled\":false,\"ignore_anti_aliasing\":false,\"ignore_rules\":[],\"name\":\"Docs\",\"notice\":null,\"open_source\":false,\"open_source_note\":null,\"open_source_pool\":false,\"open_source_withdrawn\":false,\"public\":false,\"renderer\":\"pdfbox\",\"repository_public\":false,\"repository_url\":null,\"slug\":\"docs\",\"threshold\":0.0,\"tokens_can_approve\":true}}",
"type": "text"
}
],
Expand All @@ -20,7 +20,7 @@
"forge": null,
"forge_app_installed": false,
"forge_webhook_at": null,
"gallery_enabled": true,
"gallery_enabled": false,
"ignore_anti_aliasing": false,
"ignore_rules": [],
"name": "Docs",
Expand Down
4 changes: 3 additions & 1 deletion frontend/content/docs/gallery.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ Two examples: VisualCI's own [screenshots page](/screenshots/) and the images on

## Choose what's public

Name groups of screenshots in `visualci.yml`. Nothing is public unless a group includes it:
First turn the gallery on: a new project's gallery is off, so nothing it names is public until someone with admin rights switches it on in the project's **Settings** tab, or with `update_project` and `gallery_enabled: true` over MCP. While it's off, each build whose `visualci.yml` names a gallery says so in its warnings.

Then name groups of screenshots in `visualci.yml`. Nothing is public unless a group includes it:

```yaml
gallery:
Expand Down
2 changes: 1 addition & 1 deletion frontend/content/docs/reference/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ The build's page shows the file it was sent, and `get_build` returns it as `conf
| `ci_mode` | `review`, `wait` or `strict`. The file can only make the project's mode stricter (in that order); a looser value is ignored, with a warning on the build. See [GitLab CI](/docs/ci/gitlab/#reviewing-without-a-github-check). |
| `group_depth` | Large suites: how many leading path segments of a snapshot's name make its group, for runs checked by group (500 or more snapshots). By default, all but the last two. See [Large suites](/docs/reference/credits/#large-suites). |
| `uploads` | What a bare `visualci upload` sends: a list of `path` (relative to the file), with optional `from` (`jest`, `vitest`, `insta`, `syrupy`, `rspec` or `auto`), `prefix` and `format`. |
| `gallery` | Screenshots to publish at public URLs, in groups: `groups` is a list of `name`, an optional `title`, and `include` (snapshot globs). Nothing is public unless a group includes it. See [Public gallery](/docs/gallery/). |
| `gallery` | Screenshots to publish at public URLs, in groups: `groups` is a list of `name`, an optional `title`, and `include` (snapshot globs). Nothing is public unless a group includes it and the project's gallery is on (a new project's starts off). See [Public gallery](/docs/gallery/). |

Unknown fields are errors, so a misspelt field doesn't pass unnoticed.

Expand Down
2 changes: 1 addition & 1 deletion skills/visualci-config/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ The build's page shows the file it was sent, and `get_build` returns it as `conf
| `ci_mode` | `review`, `wait` or `strict`. The file can only make the project's mode stricter (in that order); a looser value is ignored, with a warning on the build. See [GitLab CI](https://visualci.com/docs/ci/gitlab.md#reviewing-without-a-github-check). |
| `group_depth` | Large suites: how many leading path segments of a snapshot's name make its group, for runs checked by group (500 or more snapshots). By default, all but the last two. See [Large suites](https://visualci.com/docs/reference/credits.md#large-suites). |
| `uploads` | What a bare `visualci upload` sends: a list of `path` (relative to the file), with optional `from` (`jest`, `vitest`, `insta`, `syrupy`, `rspec` or `auto`), `prefix` and `format`. |
| `gallery` | Screenshots to publish at public URLs, in groups: `groups` is a list of `name`, an optional `title`, and `include` (snapshot globs). Nothing is public unless a group includes it. See [Public gallery](https://visualci.com/docs/gallery.md). |
| `gallery` | Screenshots to publish at public URLs, in groups: `groups` is a list of `name`, an optional `title`, and `include` (snapshot globs). Nothing is public unless a group includes it and the project's gallery is on (a new project's starts off). See [Public gallery](https://visualci.com/docs/gallery.md). |

Unknown fields are errors, so a misspelt field doesn't pass unnoticed.

Expand Down
Loading