Skip to content

Fix/fill custom algo form - #131

Open
filiperochalopes wants to merge 4 commits into
OpenConceptLab:mainfrom
filiperochalopes:fix/fill-custom-algo-form
Open

filiperochalopes wants to merge 4 commits into
OpenConceptLab:mainfrom
filiperochalopes:fix/fill-custom-algo-form

Conversation

@filiperochalopes

@filiperochalopes filiperochalopes commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

PR Notes — fix/fill-custom-algo-form

TL;DR: The custom algorithm form now fills canonical_url from the algorithm's discovery GET, finds that metadata on up to three URLs, and no longer flags an algorithm as conflicting with itself. No tracking issue linked.


Main Changes

Area Files Description
Custom algorithm form src/components/map-projects/MultiAlgoSelector.jsx (+9/−17) Apply discovered metadata (including canonical_url) to the form; verify the endpoint through the metadata fallback; use conflictingFields for ID/name conflicts; drop the unused filter import.
Metadata handling src/components/map-projects/customAlgoMetadata.js (+39/−0) metadataFields (valid canonical_url only), fetchAlgorithmMetadata (three-step GET discovery) and conflictingFields (ID/name conflicts against other algorithms).
Shared validation src/components/map-projects/algorithms.jsx (+2/−7) Import and re-export isLikelyCanonicalUrl from the new module, so existing imports keep working.
Tests src/components/map-projects/__tests__/customAlgoMetadata.test.js (+132/−0) Metadata extraction, discovery order, authentication errors, conflict rules, and real GET requests to disposable local HTTP servers.

Net diff against origin/main: 4 files, +182/−24. Commits: 2370122, 3198b26, c800ed0, 74f1b88.


Discovery order

The configured URL is the one the Mapper POSTs $match to; discovery only changes which URLs are read with GET. Example for https://host/api/ciel-bridge-rxnorm/$match:

Step GET URL Stops when
1 https://host/api/ciel-bridge-rxnorm/match the response has name and ID/id
2 https://host/api/ciel-bridge-rxnorm/$match same
3 https://host/api/ciel-bridge-rxnorm same

A URL without $ is requested once. Query strings, fragments and a trailing slash are preserved. If every step fails, a 401/403 from any step is the reported error (token-required feedback); otherwise the last response is.


Key Decisions

Decision Choice Rationale
Canonical URL source Use canonical_url from the GET when it is a valid http(s) URL. The field is required and was always empty although the ICD agent already returns it. An absent or invalid value keeps what the user typed.
Discovery URLs Without $, original, then parent path. Servers expose the describe route at different paths (FastAPI services register GET /api/<name> next to POST /api/<name>/$match).
Authentication failures Keep a 401/403 over a later 404. The form needs to ask for a token, not report "not found".
Conflict check Compare only against the other algorithms; evaluate ID and name separately. The previous check included the algorithm being edited, so blurring API URL or Token re-applied its own ID/name and showed "Conflicting ID/Name". Clearing one error no longer clears the other.
Helper placement New .js module instead of algorithms.jsx. algorithms.jsx imports React/MUI and cannot be loaded by node --test.

Verification Checklist

npm test
npm run test:integration
npm run eslint
./node_modules/.bin/webpack --mode development --env NODE_ENV=development --output-path <scratch dir>
  • npm test: 681 passed, 0 failed (baseline before this branch: 667).
  • npm run test:integration: 11 passed.
  • npm run eslint: no findings.
  • Development Webpack build compiled successfully.
  • Discovery tested with real GET requests against local HTTP servers (steps 1→2 and 1→2→3).
  • Conflict regression: a test failed before the fix, and an algorithm no longer conflicts with itself.
  • Verify in the browser: ICD Agent form, edit API URL then leave the field; Canonical URL is filled and ID/Name show no conflict.
  • Verify a genuinely duplicated ID/name still shows the conflict in the browser.

@filiperochalopes
filiperochalopes marked this pull request as ready for review November 16, 2026 20:53
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 16, 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-16T20:59:32.421938Z 3198b26 Draft marked ready
ℹ️ 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: 3198b26e7c

ℹ️ 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".

name: data.name || '',
description: data.description || '',
});
updateSelected(key, metadataFields(data));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve duplicate-ID detection when adding canonical metadata

If two configured custom endpoints report the same ID, name and description but different valid canonical URLs, including canonical_url in this patch prevents updateSelected's filter(value, patch) from matching the first row. The second row therefore receives no conflict error, whereas the previous three-field patch detected the duplicate. This matters because MapProject.getAlgoDef selects the first configuration by ID and mergeIntoRowMatchState removes existing candidates with the incoming algorithm_id, so the endpoints can overwrite each other's results. Validate ID/name uniqueness independently of the full metadata patch.

Useful? React with 👍 / 👎.

@snyaggarwal snyaggarwal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Reviewed at 3198b26. I ran the new test file locally and all 7 tests pass.

Filling the canonical URL from metadata and sharing the validator both look good. Two things I'd change before merging, plus one question (details inline):

  1. Probe order. The stripped /match path is now requested before the configured $match URL. Endpoints that work today now take two requests, and they can pick up the wrong document. Trying the configured URL first, with the stripped path as the fallback, avoids both.
  2. Duplicate ID/name check. I agree with the Codex comment. Adding canonical_url to the patch weakens the conflict check in updateSelected. A fix is suggested inline.
  3. Question: should metadata overwrite a canonical URL the user typed by hand?

The PR's browser check is still unticked. It's worth running against a server that serves metadata only on $match, to confirm the extra 404 on /match doesn't show up anywhere in the form.

export const fetchAlgorithmMetadata = async (url, get) => {
const [path] = url.split(/[?#]/, 1)
const metadataUrl = path.replace(/\/\$([^/]+)(\/?)$/, '/$1$2') + url.slice(path.length)
const first = await get(metadataUrl)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This changes the request for endpoints that work today. If a GET on $match already returns metadata, we now send a GET to /match first. If that path returns any JSON with name and id, we fill the form from the wrong document and never ask the configured URL. Examples: a FHIR read of a resource with id match or translate (ConceptMap/$translate becomes ConceptMap/translate), or an unrelated REST resource.

Try url first, and fall back to the stripped path only when the response isn't usable metadata. Current endpoints then stay at one request, and the configured URL stays authoritative. The 401/403 preference would work the same way with the order swapped.

Was there a server that needed the stripped path first?

name: data.name || '',
description: data.description || '',
});
updateSelected(key, metadataFields(data));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Two things about this patch:

  • Agree with the Codex note. updateSelected runs filter(value, patch) with the whole patch. With canonical_url added, two endpoints that share an ID and name but have different canonical URLs no longer get flagged. description already had the same gap, and the row also matches itself on re-verify. Checking id and name separately, against the other rows only, fixes all three. For example, filter(value, v => v.__key !== key && v.id === patch.id) for the ID error, and the same for name.
  • Hand-entered values get replaced. A valid canonical_url from metadata now replaces what the user typed, on every URL or token blur. That matches how id, name and description already behave, so it may be fine. But if someone corrects the canonical URL by hand, the next check silently reverts it. Filling it only when the field is empty would avoid that. Your call.

@@ -0,0 +1,27 @@
// Match the form's URL validation when accepting metadata from a custom API.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: this is now the form's validator itself, so "Match the form's URL validation" reads oddly. The old comment in algorithms.jsx explained why custom algorithms need it (concept_identity.canonical_url must be a URL). Worth bringing that over.

@snyaggarwal

Copy link
Copy Markdown
Contributor

There's no ticket for this change. The PR body says no tracking issue is linked, and the commits don't reference one. Please file a ticket in OpenConceptLab/ocl_issues first, describing the problem (custom algorithm form not filling the canonical URL from metadata, and servers that serve discovery on the path without $). Then reference it in the PR title and commit messages (OpenConceptLab/ocl_issues#<n> | ...), so the change can be tracked and prioritized before merge.

This branch has not been deployed

No deployments
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.

2 participants