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
9 changes: 9 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ jobs:
cp -r client/dist/. /var/www/html/project2/
chmod -R a+rX /var/www/html/project2
curl -fsS -o /dev/null -w 'GET /project2/ : %{http_code}\n' http://localhost/project2/
# Client-side routes must fall back to index.html (#82). Without the
# FallbackResource in docs/VM-setup.md this is an Apache 404.
curl -fsS -o /dev/null -w 'GET /project2/album/1 : %{http_code}\n' http://localhost/project2/album/1
# Deploy the API. The unit runs `node dist/index.js` out of
# ~/T19-Project-2/server, so that directory has to hold the build of the
Expand Down Expand Up @@ -423,3 +426,9 @@ jobs:
echo "::error::GET /project2/ failed"
exit 1
fi
if curl -fsS -o /dev/null http://localhost/project2/album/1; then
echo " GET /project2/album/1 200 ok"
else
echo "::error::GET /project2/album/1 failed: Apache has no SPA fallback (#82)"
exit 1
fi
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ Search is case-insensitive: `BLUE` should return the same matches as `blue`.

## Infrastructure

PostgreSQL and the GraphQL API run directly on the group VM. Apache serves the frontend at http://it2810-19.idi.ntnu.no/project2/ and proxies `/graphql` to the API on port 3001. The API runs as the `crate-api.service` systemd service.
PostgreSQL and the GraphQL API run directly on the group VM. Apache serves the frontend at http://it2810-19.idi.ntnu.no/project2/, falls back to `index.html` for client-side routes such as album pages, and proxies `/graphql` to the API on port 3001. The API runs as the `crate-api.service` systemd service.

CI uses a self-hosted runner on the VM. Pushes to `main` run the project checks and deploy the frontend and backend. See [VM setup](docs/VM-setup.md) for deployment and verification steps.

Expand Down
7 changes: 7 additions & 0 deletions docs/AI-USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ the part that matters most.
| 2026-11-04 | erikhfj | opencode | #22, scalability measurements at 100,000 and 1,000,000 albums. The tool produced tidy numbers that hid an inconvenient result: cursor paging was only ~3x faster than `OFFSET`, because no index supports the sort key and both approaches scan and sort. I ran the extra experiment with a composite `(lower(title), id)` index, saw the page drop from 295 ms to 0.09 ms, and documented the missing index as a follow-up rather than quietly claiming cursor paging is constant time. Also corrected an earlier claim in the README that every prefix query uses the GIN index: at 1M a broad prefix is planned as a sequential scan, and it should be documented as such. |
| 2026-11-04 | erikhfj | opencode | #30, GraphQL codegen. Caught two things the first draft got wrong: a fixture operation in `CrateButton.test.tsx` was being plucked into the document map and would have shipped in the bundle, and `DateTime` had no scalar mapping so `createdAt` became `unknown`. Verified the acceptance criterion by renaming `averageRating` in the schema and watching `pnpm build` fail with the suggested field name, then restoring it. Measured the bundle (418 kB raw) instead of assuming the generated document map was free |
| 2026-11-04 | erikhfj | opencode | #76, `myCrate` and the crate page. The paging test caught a type mismatch I would have missed by reading: `crate_item.added_at` is a `Date` column while `review.created_at` is in string mode, so the cursor had to rebuild a `Date`. The axe run caught a heading-order violation (page h1 straight to the card h3) that the markup looked fine without. I chose the empty-connection behaviour for anonymous requests myself and wrote it into decision 5 rather than leaving it implicit |
| 2026-11-05 | erikhfj | opencode | #77 review: evenkkl found that the crate cursor kept milliseconds while `added_at` stores microseconds, so paging could skip rows saved inside the same millisecond. Reproduced it first, four saves inside one tick returned 2 of 5 items, then carried the database text in the cursor with `to_char` and validated the calendar date before it reached SQL. The row-comparison rewrite was mine: EXPLAIN showed the OR form was only a filter. |
| 2026-11-05 | erikhfj | opencode | #72 review: rachelks pointed out the guard missed individual skipped tests. The cause was narrower than a missing check: Vitest reports `skipped`, the script counted jest's `pending`, so the counter was always zero. Demonstrated the old and the new script on the same report (exit 0 against exit 1) and covered `checkReport` with eight tests. |
| 2026-11-06 | erikhfj | opencode | #73 review: I had benchmarked the row comparison while `searchAlbums` runs an OR, so the numbers did not describe the API. Measuring both against one index showed the OR is slower than no index at depth, 322 ms against 254 ms, which makes the index and the predicate one change rather than two. Updated the follow-up issue to match. |
| 2026-11-06 | erikhfj | opencode | #78 and #79 review fixes: a test that clicks Remove from crate and checks the list, not only that the button exists, and a sentence in this log that stopped mid-word. Confirmed the new test fails when the refetch mock still returns the album, so it does not pass on a stale render. |
| 2026-11-07 | erikhfj | opencode | #73 and #78: the UI said I had dismissed teammates' approvals, which nobody had done. The event timeline showed Gitea's own `review_dismissed` with "The merge-base changed after approval.", stored base 3031a33 against a merge base of 3fd5067 after #72 landed, so every approval was invalidated in the same second. Merging main into both branches fixed it. |
| 2026-11-09 | evenkkl | Claude | #82, Apache SPA fallback for album pages. A teammate reported the Apache 404 on `/project2/album/:id`; Claude traced it to the missing `index.html` fallback (links are full page loads from `BASE_URL`, and the Vite server hides the problem locally) and drafted the issue. Even chose to file the issue first and fix it separately. The fix is a `FallbackResource` in the VM's Apache config, documented in `VM-setup.md`, plus a deploy check that `/project2/album/1` returns 200 so the job fails if the fallback is ever lost. |
| 2026-11-09 | erikhfj | opencode | #85 review: checked the Apache fallback in a browser (direct deep link, reload, click-through), not only with curl, and applied it on the VM as a `conf-available` file. Two things came out of it: `grep -r` skips the symlinked `sites-enabled` files, which made the first config check a false negative, and the runbook described editing the vhost rather than the setup that was used. |

## Notes

Expand Down
50 changes: 50 additions & 0 deletions docs/VM-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,55 @@ ProxyPass /graphql http://127.0.0.1:3001/graphql
ProxyPassReverse /graphql http://127.0.0.1:3001/graphql
```

Album pages and other client-side routes such as `/project2/album/42` have no
file behind them, so Apache must serve `index.html` for them and let React
handle the route. Without this, opening or reloading a deep link gives an
Apache 404 (#82). The fallback lives in its own conf file rather than in the
site config, so it survives edits to the vhost and can be removed on its own:

```bash
sudo tee /etc/apache2/conf-available/project2-spa.conf >/dev/null <<'EOF'
# SPA fallback: client routes such as /project2/album/42 have no file behind them.
# Scoped to the app directory so /graphql (ProxyPass) and built assets are untouched.
<Directory /var/www/html/project2>
FallbackResource /project2/index.html
</Directory>
EOF
sudo a2enconf project2-spa
sudo /usr/sbin/apachectl configtest
sudo systemctl reload apache2
```

`apachectl configtest` must print `Syntax OK` before the reload. Then check the
deep link, a built asset and the proxy together:

```bash
curl -s -o /dev/null -w 'deep link %{http_code}\n' http://localhost/project2/album/1
asset=$(ls /var/www/html/project2/assets/*.js | head -1)
curl -s -o /dev/null -w "asset %{http_code} %{content_type}\n" \
"http://localhost/project2/assets/$(basename "$asset")"
curl -s -o /dev/null -w 'graphql %{http_code}\n' -X POST http://localhost/graphql \
-H 'content-type: application/json' -d '{"query":"{ __typename }"}'
```

The asset must return `200` with a JavaScript content type. If it returns
`text/html`, the fallback is catching files as well and the `<Directory>` scope
is wrong. That scope is also what leaves `/graphql` alone: the proxy is
configured in `conf-available/crate-graphql.conf`, outside the app directory.
The deploy job fails if `/project2/album/1` does not return 200.

One consequence of a fallback: a genuinely missing file under
`/project2/assets/` also returns `index.html` with 200 instead of 404, so a bad
asset appears as a MIME-type error rather than a missing file. That is normal
for a single-page app.

To undo the change:

```bash
sudo a2disconf project2-spa
sudo systemctl reload apache2
```

### Verify a deployment

On the VM, check the deployed commit, service status and frontend response:
Expand All @@ -66,6 +115,7 @@ git -C ~/T19-Project-2 rev-parse HEAD
systemctl is-active crate-api
journalctl -u crate-api -n 50 --no-pager
curl -fsS -o /dev/null -w '%{http_code}\n' http://localhost/project2/
curl -fsS -o /dev/null -w '%{http_code}\n' http://localhost/project2/album/1
```

Then run the smoke tests below against the API and, if needed, through Apache.
Expand Down