Skip to content
Open
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
16 changes: 3 additions & 13 deletions services/file-service/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,9 @@ USER appuser
# passes false, so local stacks behave like the golden app.
ENV FILE_UPLOAD_ALWAYS_FAIL=true

# Click-triggered notification failure (same bake rationale as above): sharing
# a file publishes the file_shared event to a nonexistent SNS topic, so every
# share click fails with a real AWS SNS error and fires the
# NotificationEventPublishFailure alert at admin-service (incident + Devin
# session + Slack, attributed to the sharing user via reporter_email). The
# share record is still saved, but the request returns the AWS error so the
# UI shows a red failure banner. docker-compose.yml passes false, so local
# stacks behave like the golden app.
ENV FILE_SHARE_EVENT_ALWAYS_FAIL=true

# With uploads failing permanently (above), users would have no files to share.
# Seeding gives every user a few demo documents on their first file listing,
# so the share-notification failure is demoable alongside the upload failure.
# With uploads failing permanently (above), users would have no files to work
# with. Seeding gives every user a few demo documents on their first file
# listing, so the upload failure is demoable with existing content in place.
# docker-compose.yml passes false, so local stacks behave like the golden app.
ENV FILE_SEED_DEMO_DOCS=true

Expand Down
60 changes: 60 additions & 0 deletions services/file-service/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,66 @@ mod tests {
assert!(parse_bool_env("OTTERWORKS_DEFINITELY_UNSET_ENV_VAR", true));
}

fn dockerfile_enables_share_event_failure(dockerfile: &str) -> bool {
let dockerfile = dockerfile.replace("\\\r\n", " ").replace("\\\n", " ");

dockerfile
.lines()
.map(str::trim)
.filter_map(|line| {
let (instruction, rest) = line.split_once(char::is_whitespace)?;
instruction
.eq_ignore_ascii_case("ENV")
.then_some(rest.trim_start())
})
.any(|env| {
if env.contains('=') {
env.split_whitespace().any(|assignment| {
assignment
.strip_prefix("FILE_SHARE_EVENT_ALWAYS_FAIL=")
.is_some_and(|value| parse_bool(value.trim_matches(['"', '\'']), false))
})
} else {
env.strip_prefix("FILE_SHARE_EVENT_ALWAYS_FAIL")
.is_some_and(|value| {
value.starts_with(char::is_whitespace)
&& parse_bool(value.trim().trim_matches(['"', '\'']), false)
})
}
})
}
Comment on lines +151 to +178

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

📝 Info: Regression guard covers the relevant ENV forms

dockerfile_enables_share_event_failure joins continuations and parses both ENV KEY=value and ENV KEY value forms, handling quotes, case, comments, and prefix collisions like FILE_SHARE_EVENT_ALWAYS_FAIL_OTHER. The primary reintroduction form is covered.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.


#[test]
fn image_does_not_force_share_event_failures() {
assert!(!dockerfile_enables_share_event_failure(include_str!(
"../Dockerfile"
)));
}

#[test]
fn share_event_failure_detection_handles_env_syntax_variants() {
for line in [
"ENV FILE_SHARE_EVENT_ALWAYS_FAIL=true",
"env FILE_SHARE_EVENT_ALWAYS_FAIL=1",
"ENV FILE_SHARE_EVENT_ALWAYS_FAIL true",
"ENV FILE_SHARE_EVENT_ALWAYS_FAIL=\"true\"",
"ENV FILE_UPLOAD_ALWAYS_FAIL=true FILE_SHARE_EVENT_ALWAYS_FAIL=true",
"ENV FILE_UPLOAD_ALWAYS_FAIL=true \\\n FILE_SHARE_EVENT_ALWAYS_FAIL=true",
] {
assert!(dockerfile_enables_share_event_failure(line), "line={line}");
}

for line in [
"ENV FILE_SHARE_EVENT_ALWAYS_FAIL=false",
"ENV FILE_SHARE_EVENT_ALWAYS_FAIL false",
"ENV FILE_SHARE_EVENT_ALWAYS_FAIL_OTHER=true",
"ENV FILE_UPLOAD_ALWAYS_FAIL=true",
"# ENV FILE_SHARE_EVENT_ALWAYS_FAIL=true",
] {
assert!(!dockerfile_enables_share_event_failure(line), "line={line}");
}
}

#[test]
fn upload_always_fail_is_off_by_default() {
if std::env::var("FILE_UPLOAD_ALWAYS_FAIL").is_ok() {
Expand Down
Loading