Repository navigation
Upstreams and proxies as resources - #29
Merged
Merged
Conversation
The UI used to turn an upstream into a YAML fragment by string
concatenation and hand it to the generic patch endpoint. That had three
failure modes, and each wrote or rejected the user's only config file:
- A value with `#` or `: ` in it (a proxy password, an API key) was read
back as a comment or a mapping.
- Renaming an upstream left routes and groups pointing at the old name,
so the save was rejected by validation with no hint why.
- Deleting an upstream that a rule still used was rejected the same way.
The control plane now owns these writes:
- `POST /providers`, `PUT /providers/{name}`, `DELETE /providers/{name}`,
and the same three for `/proxies`. The body is a structure; serde does
the quoting. Omitting the key or base_url on update keeps the stored
one, since the overview only ever shows them masked. Proxy auth is
keep / none / set for the same reason.
- A rename moves every reference (rule targets, provider_would_be,
group members, a select group's choice; providers using a proxy) in
the same write, so it is one version. A delete that is still
referenced is a 409 naming who references it.
- `POST /providers/test` probes an unsaved definition with its own
protocol and proxy, through the same client builder forwarding uses.
An unsaved OAuth credential is not refreshed just to test it: the
server may revoke the refresh token on use.
- `POST /proxies/test` completes the proxy handshake, credentials
included. Measuring only the TCP connect reported a wrong password as
reachable.
Underneath, `tw-yaml` gains `put` (replace or create a value at a path,
creating missing parent maps), `remove_key` (removing an emptied parent
map too), and `replace_item`. Each re-parses and checks that the target
reads back as written and that every node outside it is unchanged, and
property tests run them against thousands of generated documents.
`tw_config::edit` builds item upserts on top: only changed fields are
written, so comments beside untouched fields survive, and a flow-style
item is rewritten as a block in place. `insert` and `clear_seq` now use
`put` instead of their own key-splicing code.
Removed without replacement, since nothing uses them any more: `/setup`
(and `generate_with_provider`), `/probe`, and the proxy and base_url
modes of `/l1`. `ProviderView` reports slugs instead of labels, plus the
credential kind, whether the protocol is explicit, the manual model list
and references; `ProxyView.used_by` lists names.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Thanks for the PR. One thing before review: this targets
No need to close and reopen: click Edit next to the PR title and change the base branch to See CONTRIBUTING.md and CONTRIBUTING.md for the branch contract. |
… after its colon Two position bugs in the structural editor, both caught while writing `pricing.auto_update` next to an existing `pricing.sheets` list: - A new key took its indentation from the first line of the parent's block. A child's byte range is its value's range, and a block-style value starts on the next line, one level deeper. When the parent's first key held a list or a mapping, the new key landed inside that list item, and the self-check refused the write. The column now comes from the direct child keys themselves. - The parser marks a blank value (`key:`) on the colon, not after it. Walking back from there finds the previous key's colon. Nodes now carry the position after the colon, so every consumer sees where the value actually goes, and the per-caller workaround is gone. Writing into `key: ` with a trailing space also stops producing `key:x`. A new property test adds a key to a random mapping of a random document, and the document generator now writes blank values. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The desktop UI built an upstream as a YAML fragment by string concatenation and sent it through the generic patch endpoint. Every failure mode of that landed on the user's only config file:
#or:read back as a comment or a mapping.The next UI edits upstreams and proxies in dialogs, so these writes need to be structural.
What
Resource endpoints (
tw-control/src/resources.rs)POST /providers,PUT /providers/{name},DELETE /providers/{name}, and the same three for/proxies. They take a structure, and serde does the quoting.base_urlkeeps the stored value, because the overview only shows them masked. Proxy auth iskeep/none/setfor the same reason.provider_would_be, group members and a select group's choice, and for proxies the upstreams using them.POST /providers/testprobes an unsaved definition with its own protocol and proxy, through the client builder forwarding uses. An unsaved OAuth credential is never refreshed just to test it.POST /proxies/testcompletes the proxy handshake, credentials included. The old TCP-only check reported a wrong password as reachable.Edit primitives
tw-yamlgains three functions:putreplaces or creates the value at a path, creating missing parent maps.remove_keyremoves a key, and its parent map too if that leaves it empty.replace_itemreplaces a list item in place.Each one re-parses and checks two things: the target reads back as written, and every node outside it is unchanged.
insertandclear_seqnow go throughputrather than their own key splicing.tw_config::editupserts items by name:tw_config::refsfinds references and renames them.Two position bugs in the editor are fixed:
key:) on the colon rather than after it. Nodes now carry the position after the colon, which removes the per-caller workaround and stopskey:with a trailing space from being written askey:x.Removed, since nothing uses them any more:
/setupandgenerate_with_provider./probe./l1.Changed views
ProviderViewreports slugs instead of labels, plus the credential kind, whether the protocol is explicit, the manual model list and references.ProxyView.used_bylists names. The username stays out of the overview, as before.Tests
putandremove_keyagainst about 2,800 generated documents each, alongside the existingsetproperty test, and compare the semantic tree before and after. A fourth adds a new key to a random mapping of each document. The generator now also writes blank values.tw-control/tests/resources.rshas 12 tests against the real config file:#and:round-trips.fmt,clippy -D warningsandcargo test --workspacepass.scripts/smoke.sh: 48 passed, 0 failed, 1 over target and not a regression (memory 35 MB against a 30 MB target; the script only counts 40 MB and above as a regression).🤖 Generated with Claude Code