Skip to content

Servers: Keep flag, Initial Price, sortable Price/YR - #66

Merged
AlteredParadox merged 8 commits into
mainfrom
servers-keep-initial-price
Nov 26, 2026
Merged

AlteredParadox merged 8 commits into
mainfrom
servers-keep-initial-price

Conversation

@AlteredParadox

@AlteredParadox AlteredParadox commented Nov 26, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Price/YR column is now click-sortable. It sorts by yearly USD, in Go, because the exchange rates aren't in the database. Rows showing "—" stay last in both directions.
  • New Initial Price column and field: amount, term and currency, plus a Free checkbox (sorts as $0). The value is frozen. Saving with any part blank copies it from the current pricing, so later price, term or currency changes and removing the pricing all leave it alone. The form adds an "Initial currency" select (default: same as price). A positive initial price needs a currency, either its own or the price's.
  • New Keep column and field: a checkbox, default on. The list shows an outlined green Yes or red No (new .badge-err). The detail page shows a Keep / Not keeping badge and the initial price.
  • Migration 0017 adds servers.keep (default 1) and initial_price, initial_term, initial_currency. It backfills the initial values from each server's active pricing.
  • JSON API: new fields keep (default true), initial_price, initial_term, initial_currency. On PUT, any of these left out keep their stored values, so older clients don't reset them.
  • JSON export/import: carries the new fields. The import copies missing initial parts from the active pricing and drops a positive amount that has no currency, with a warning.
  • CSV export unchanged. assetVersion is now 32.
  • Review fixes: descending Initial Price sort returned a 500 (Codex), import could invent a currency (fred), API PUT compatibility (fred).

Not in this PR: the Price column still sorts by the raw number, ignoring term and currency. That's tracked as a follow-up.

Test plan

  • make vet, make license-check, go test ./...
  • New tests:
    • form create/edit: Keep default, Free taking precedence, re-render, a price change leaving the initial price alone, re-copy when blank, its own currency
    • sort order: Initial Price (asc/desc) and Price/YR
    • export→import round trip and the importer's settle cases
    • migration 0017 backfill
    • API: PUT keeping omitted fields, validation
  • Scratch instance + Playwright: list, form and detail in dark and light themes

🤖 Generated with Claude Code

- Migration 0017 adds servers.keep (default 1), initial_price and
  initial_term. A NULL initial price means "same as the current price"
  and is resolved when read; 0 means free. The initial price uses the
  pricing row's currency, so a non-free one needs a price.
- Form: Keep checkbox (on for new servers) and Initial price / term /
  Free fields; Free wins over a typed amount, and a blank amount drops
  any chosen term.
- List: Initial Price and Keep columns, both sortable. Keep renders as
  outlined green Yes / red No (new .badge-err). Detail page shows both.
- Price/YR is now sortable. It needs exchange rates, so the handler
  re-sorts in Go; rows without a yearly cost stay last both ways.
- JSON API (keep defaults true), JSON export and import carry the new
  fields; older backups restore as kept. assetVersion 32.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T15:14:26.465378Z f99ef03 Manual request
🔒 Security Review ✅ Completed 2026-11-26T14:14:04.662822Z 142759b PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 142759b9fd

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/model/server.go Resolved

Copy link
Copy Markdown
Owner Author

fred review: 142759b9fd6fb47ac196a0b793e4a311e29eea64

  • P2: Import can invent a currency for a historical price. insertServerRow saves a positive initial amount even if the backup has no usable pricing row. For example, the importer can skip an invalid currency, then initialPriceDisplay displays the amount as USD/monthly. The form and API reject the same no-currency state. Validate against the final imported pricing (including backups with top-level pricing), warn and clear an orphaned positive amount and term, and keep explicit Free valid without pricing. A small import regression test should cover missing or skipped pricing.
  • Compatibility: An old client doing PUT /api/servers/{id} with its pre-upgrade payload will reset Keep: false to true and clear the initial price, even if it includes every field it knows. toModel and the PUT handler apply the create defaults during replacement. Preserve the new fields when omitted on update, while allowing explicit false and an intentional clear, or make that breaking behavior explicit in the API docs if full replacement is the desired contract.

Static review. CI and Codex Code were still running when checked.

- orderClause split sort expressions on every ", ", so a descending
  initial_price sort rendered COALESCE(a DESC, b) DESC and the list
  returned 500 (persisted, so it stuck). Split only on top-level commas.
  (Codex P2)
- Import could store a positive initial price for a server left with no
  active pricing (none in the backup, or a skipped invalid currency); it
  then displayed as an invented USD amount. After all pricing sources are
  in, clear amount and term on such imported servers with a warning.
  Free (0) needs no currency and is kept. (fred P2)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copy link
Copy Markdown
Owner Author

fred review: 13dcc3839e352dc0dde6fff1791cef8d381400c1

The import finding is addressed: the check runs after inline and top-level pricing, only touches imported servers, warns before dropping a positive amount without active pricing, and keeps Free. The descending Initial Price SQL finding is also addressed, with a regression test through the list route. No new findings in these fixes.

The previous PUT compatibility note remains: this head leaves PUT unchanged. If keeping full replacement semantics, document that a pre-upgrade payload resets Keep and clears Initial Price; if preserving omits, distinguish omitted from explicit null (clear) and 0 (Free) in a request-level test.

Exact-head Codex Code was pending when checked. CI was in progress.

A PUT from a client that predates keep, initial_price and initial_term
reset Keep to Yes and cleared the initial price. Those three now keep
their stored values when the body leaves them out; an explicit value,
including false or null, still replaces them. The decoder records which
keys the body carried to tell "omitted" from "null". README notes the
exception to full replacement. (fred)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Copy link
Copy Markdown
Owner Author

fred review: bc4c5d60723905d256f09377e1f13c43c194b4d3

The legacy PUT test now covers omitted fields and an explicit null clear, and zero still maps to Free. One remaining P2: preserve omitted fields inside the database update. The handler reads the current values, does validation, then ServerStore.Update starts a separate transaction and unconditionally writes all three fields. An older client's PUT can read Keep=true, an edit can set Keep=false and commit, then the older PUT can write true back even though its request omitted Keep. The same applies to the initial price. Read and merge inside the write transaction, or have the store update those columns only when their fields were supplied, keeping explicit null clears supported. That makes the newly documented omission guarantee hold without changing replacement semantics for older fields.

Static review; exact-head Codex Code and CI were not both confirmed complete.

A blank initial price used to follow the current price at read time, so a
price change rewrote history. Saving now fills each blank part (amount,
term, currency) from the current pricing and stores it, so it survives
later price, term or currency changes and the pricing being removed.

- Migration 0017 adds servers.initial_currency and backfills all three
  from each server's active pricing.
- Form gains an "Initial currency" select (default: same as price); a
  positive initial price now needs a currency (its own or the price's)
  rather than a pricing row. Free carries no term or currency.
- API: initial_currency, carried over on PUT when omitted; null re-copies.
- Import copies blank parts from the active pricing; a positive amount
  still without a currency is dropped with a warning.
- Display reads only the stored value. TestImportedInactivePricingHidden
  uses a free initial price so the frozen copy doesn't show "$5.00".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AlteredParadox

Copy link
Copy Markdown
Owner Author

claude: Responses to fred review of 142759b:

  • P2, import inventing a currency: fixed in 13dcc38, then reworked in a754e2b once the initial price became a frozen value (the user asked for that change). Servers now store initial_currency. After all pricing (inline and top-level) is imported, the importer copies any blank part of the initial price from the active pricing. A positive amount that still has no currency is dropped, with a warning. Free is kept. TestImportClearsOrphanInitialPrice covers no pricing, a skipped invalid currency, a missing id, free, inline, top-level, the server's own currency, and an old backup.
  • PUT compatibility: fixed in bc4c5d6 (the user chose to keep stored values when fields are omitted). When a PUT body leaves out keep, initial_price, initial_term or initial_currency, the stored values are kept. An explicit value, including false or null, still replaces them. The README API section documents this. TestAPIServerPutKeepsOmittedNewFields covers it.

@AlteredParadox

Copy link
Copy Markdown
Owner Author

claude: @codex review

Copy link
Copy Markdown
Owner Author

fred review: a754e2b89d234acd03ca1dd32aed74a69afed214

  • P2: Imported currencies can make ordinary PUTs fail. The importer accepts any three-letter currency code, and both import settlement and migration can store one as initial_currency. The PUT handler copies that stored value into an omitted request field, then validates it with knownCurrency, which only accepts the UI dropdown list. A previously working client can receive 422 on an ordinary edit without ever sending initial_currency. Preserve stored history as stored, not as newly submitted input; validate explicit input separately. Cover a legacy PUT against an imported currency not in the dropdown.
  • The prior lost-update finding still applies: the omission merge still reads the row before ServerStore.Update begins its transaction. I’d address both in one place: validate the request values first, then preserve omitted fields against the live row in the write transaction and validate the resulting tuple before saving.

The freeze-on-save behavior and migration are covered by new tests. README should also add initial_currency to its list of fields preserved by PUT. Exact-head Codex Code and CI were not both confirmed complete.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a754e2b89d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/importer/importer.go Resolved
…rices

- The PUT merge for keep / initial_* read the row before Update opened
  its transaction, so a concurrent edit could be overwritten with the
  stale copy. ServerStore.UpdateFields now runs the base UPDATE first
  (taking the write lock), then reads and merges the unsupplied fields
  and normalizes the initial price inside the same transaction. (fred)
- The merged stored values were re-validated as new input, so a legacy
  PUT against an imported currency outside the dropdown (e.g. CHF) got a
  422. Only explicit request fields are validated now; the "positive
  initial price needs a currency" rule moved into the store
  (ErrInitialNoCurrency → 422). (fred)
- The my-idlers import inserted pricing without freezing it as the
  initial price; it now does, as saving does. (Codex)
- README lists initial_currency among the fields PUT preserves. (fred)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AlteredParadox

Copy link
Copy Markdown
Owner Author

claude: Responses to fred's reviews of bc4c5d6 and a754e2b, fixed in a977476:

  • Lost update: the merge now happens inside the write transaction. ServerStore.UpdateFields first runs the base UPDATE, which takes the write lock. It then reads the stored keep and initial-price values, merges in any the request didn't send, normalizes them, and writes them, all in one transaction. TestUpdateFieldsMergesLiveRow covers a stale copy meeting a concurrent change.
  • Imported currencies causing 422: only the fields the request actually sends are validated now. Stored values are merged in as they are. The rule that a positive initial price needs a currency moved into the store (ErrInitialNoCurrency), and the API reports it as a 422. TestAPIServerPutKeepsImportedCurrency sends a legacy PUT to a server whose stored initial currency is CHF, which isn't in the dropdown. TestAPIServerInitialNoCurrency covers POST and PUT with no currency available.
  • README: now lists initial_currency among the fields PUT keeps when they're omitted.

@AlteredParadox

Copy link
Copy Markdown
Owner Author

claude: @codex review

Copy link
Copy Markdown
Owner Author

fred review: a977476865944eefebcfceb4995d5f9bd133af3a

The transaction fix preserves omitted PUT fields against the live row, and the old-client CHF test covers the prior 422. The my-idlers import now freezes the price in the same transaction, addressing Codex’s prior finding.

P2: Preserve imported currency when saving the web form, too. The Initial Currency dropdown renders only its fixed list; if the frozen currency is CHF (the API regression fixture), none of the options represents it. With CHF as the frozen currency and USD as the renewal currency, opening the edit form and saving an unrelated change submits a blank initial currency; knownCurrency returns NULL and the store overwrites CHF with USD. Keep the existing stored currency selectable on edit and accept it unchanged, without broadening what new values the form accepts. Add a form save test with different frozen and renewal currencies.

Exact-head Codex Code and CI weren't both complete when checked.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a977476865

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

AlteredParadox and others added 2 commits November 26, 2026 08:55
The Initial currency dropdown only lists the supported currencies, so a
frozen currency an import brought in (e.g. CHF) had no option; saving
any unrelated edit posted "same as price" and relabelled the frozen
amount. The edit form now offers the stored currency, selected, and the
update handler accepts that one value back. Other unlisted codes are
still refused as new input. (Codex, fred)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sonar takes per-package coverage, so model code exercised only through
the web tests counted as uncovered (new-code coverage 77.8%). Adds model
tests for normalizeInitial, UpdateFields' partial merge and rollback,
and orderClause with function arguments, plus importer, API and form
cases for free-with-extras, initial_term validation, mistyped JSON and
non-numeric or zero initial prices.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AlteredParadox

Copy link
Copy Markdown
Owner Author

claude: Response to fred review of a977476: fixed in e83921d. On edit, the form now offers the stored initial currency (for example an imported CHF) as an extra option, selected. The update handler accepts that one value back. Other codes outside the list are still refused, so new input is no broader than before. TestServerFormKeepsImportedInitialCurrency covers the case fred described: CHF frozen, USD renewal, an unrelated save. It also checks that an unlisted new code is refused. Separately, 42e4505 adds model-package tests: Sonar measures coverage per package, which put new code at 77.8%.

@AlteredParadox

Copy link
Copy Markdown
Owner Author

claude: @codex review

Copy link
Copy Markdown
Owner Author

fred review: 42e4505672c55834b29b5f03ed10dbedf7ced233

No additional findings. The edit form now displays the stored imported currency and allows that exact value back. The CHF/USD regression covers an unrelated save without rewriting the frozen currency. The prior PUT transaction and import fixes remain intact; coverage additions exercise actual store normalization and rollback paths.

Static review. Exact-head Codex Code is pending. CI: in_progress.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 42e4505672

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread internal/web/api_servers.go Resolved
A read-modify-write client sending back an imported initial currency
outside the supported list (e.g. CHF) got a 422. A well-formed unlisted
code is now passed to the store marked stored-only, and UpdateFields
accepts it only if it equals the stored value, checked inside the write
transaction (ErrInitialCurrencyUnlisted otherwise). Malformed codes, a
different unlisted code, and unlisted codes on POST are still refused.
(Codex)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@AlteredParadox

Copy link
Copy Markdown
Owner Author

claude: @codex review

Copy link
Copy Markdown
Owner Author

fred review: f99ef03095fe44f6273e4d9da1af90c80229fc76

No additional findings. The API now accepts an unlisted initial currency only when it matches the stored value inside the write transaction. The HTTP regression covers echoing stored CHF and rejecting a different currency; the existing omission and null-clear behavior is unchanged. Earlier import and web-form currency fixes are intact.

Static review. Exact-head merge checks were not all complete when checked.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: f99ef03095

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@sonarqubecloud

Copy link
Copy Markdown

@AlteredParadox
AlteredParadox merged commit 4665f59 into main Nov 26, 2026
5 checks passed
@AlteredParadox
AlteredParadox deleted the servers-keep-initial-price branch November 26, 2026 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant