Skip to content

Fix batch of bugs: Dockerfile, duplicate HTML attrs, nil guards#68

Merged
dyoung522 merged 4 commits intomainfrom
fix/batch-bug-fixes
Feb 10, 2026
Merged

Fix batch of bugs: Dockerfile, duplicate HTML attrs, nil guards#68
dyoung522 merged 4 commits intomainfrom
fix/batch-bug-fixes

Conversation

@dyoung522
Copy link
Contributor

Changes

Fixes all 4 identified bugs in one batch:

#58 — Dockerfile rewrite

  • Multi-stage build (build stage + slim runtime stage)
  • Removed Node.js and Yarn (not needed with importmaps)
  • Runs as non-root user
  • Significantly smaller image

#59 — Duplicate class attribute in _mod.html.erb

  • Merged duplicate class attributes into one
  • Kept the cursor-pointer and lighter hover styles

#62 — Duplicate </header> in layout

  • Removed inline </header> that caused a stray closing tag

#64 — Analytics partial nil guards + CSS bug

  • Added nil checks for metadata, metadata[:errors], metadata[:warnings]
  • Fixed type == :errortype == :errors so red CSS actually applies to errors
  • Added safe navigation (&.dig) in show view
  • Graceful fallback when no analytics data available

Closes #58, closes #59, closes #62, closes #64

Copilot AI review requested due to automatic review settings February 10, 2026 00:37
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR batches several fixes across the Rails app’s views and containerization to address broken/stale Docker builds, invalid HTML, and analytics rendering edge cases.

Changes:

  • Rewrites the Dockerfile to a multi-stage build, removes Node/Yarn, and runs the app as a non-root user.
  • Fixes invalid HTML in views (duplicate class attribute, stray </header>).
  • Adds nil-guarding/fallback rendering for analytics metadata and corrects error vs warning CSS targeting.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
Dockerfile Switches to multi-stage build with slimmer runtime image and non-root execution.
app/views/mods/_mod.html.erb Removes duplicate class attribute by merging classes.
app/views/layouts/application.html.erb Fixes malformed header markup by removing an extra closing tag.
app/views/mods/_analytics.html.erb Adds guards/fallback UI for missing analytics data and fixes error styling condition.
app/views/mods/show.html.erb Uses safe navigation when passing analytics metadata to the partial.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

</button>
<div class="mt-12 min-h-48">
<%= render("analytics", metadata: @mod.metadata[:status]) if params[:analytics] %>
<%= render("analytics", metadata: @mod.metadata&.dig(:status)) if params[:analytics] && @mod.metadata.present? %>
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

The extra && @mod.metadata.present? guard prevents rendering the analytics partial when @mod.metadata is nil, so the partial can’t show its new "No analytics data available" fallback. Consider rendering whenever params[:analytics] is set and pass @mod.metadata&.dig(:status) (letting the partial handle nil).

Suggested change
<%= render("analytics", metadata: @mod.metadata&.dig(:status)) if params[:analytics] && @mod.metadata.present? %>
<%= render("analytics", metadata: @mod.metadata&.dig(:status)) if params[:analytics] %>

Copilot uses AI. Check for mistakes.
</button>
<div class="mt-12 min-h-48">
<%= render("analytics", metadata: @mod.metadata[:status]) if params[:analytics] %>
<%= render("analytics", metadata: @mod.metadata&.dig(:status)) if params[:analytics] && @mod.metadata.present? %>
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

This change is intended to make analytics rendering resilient to missing metadata, but the existing request specs only cover the case where metadata[:status] is present. Please add a request spec for analytics=true when @mod.metadata (or metadata[:status]) is nil/blank to assert the fallback behavior (e.g., "No analytics data available").

Copilot uses AI. Check for mistakes.
Comment on lines +45 to +49
# Run as non-root user
RUN groupadd --system rails && \
useradd rails --system --gid rails --home /rails && \
chown -R rails:rails /rails
USER rails:rails
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

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

The image now runs as the non-root rails user, but the deployment config mounts a named volume at /rails/tmp (config/deploy.yml). Docker volumes are typically owned by root on first create, which can cause runtime failures when Puma/Rails tries to write pid/cache files under tmp/. Consider adding an entrypoint that chowns /rails/tmp at container start (then drops privileges), or adjust the volume/user strategy so /rails/tmp is writable by the rails user.

Copilot uses AI. Check for mistakes.
- Rewrite Dockerfile with multi-stage build, remove unused Node/Yarn (#58)
- Fix duplicate class attribute on tr in _mod.html.erb (#59)
- Fix duplicate </header> closing tag in layout (#62)
- Add nil guards to analytics partial + fix CSS class bug (#64)

Closes #58, closes #59, closes #62, closes #64
- New spec file for _analytics.html.erb partial (nil guards, error/warning rendering)
- Add nil metadata context to show.html.erb spec
- All 230 specs passing
- Remove redundant metadata.present? guard in show view; let the
  partial handle nil metadata with its fallback message
- Add docker-entrypoint.sh to ensure tmp dirs are writable
  (Docker volumes mount as root, but app runs as non-root user)
- Update spec to verify nil metadata shows fallback message
@dyoung522 dyoung522 merged commit 0dbf8e6 into main Feb 10, 2026
2 checks passed
@dyoung522 dyoung522 deleted the fix/batch-bug-fixes branch February 10, 2026 01:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants