[PR #13703] refactor: extract shared Provider.filter and resolveNetworkOptions explicit flags #14781

Open
opened 2026-02-16 18:19:32 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/13703

State: open
Merged: No


Summary

  • Extract Provider.filter(config) function to eliminate repeated disabled/enabled provider filtering across 3 files
  • Add explicit flag tracking to resolveNetworkOptions return value, removing process.argv.includes duplication in thread.ts

Motivation

Provider filtering logic (Set creation from disabled_providers/enabled_providers + predicate check) was duplicated in:

  • provider.ts state() closure
  • server/routes/provider.ts route handler
  • cli/cmd/auth.ts auth flow

Similarly, thread.ts re-checked process.argv.includes("--port") etc. after calling resolveNetworkOptions because the function didn't expose which flags were explicitly set.

Changes

Provider.filter extraction

  • Added Provider.filter(config) returning { disabled: Set, allowed(id): boolean }
  • Updated provider.ts state() to use pf.allowed() for final filter and pf.disabled.has() for assembly guards
  • Replaced inline Set creation + filtering in routes/provider.ts and auth.ts
  • Standardized null (was inconsistent null vs undefined) for missing enabled_providers

resolveNetworkOptions explicit flags

  • Extracted pure resolveFrom(args, config, argv) function for testability
  • Added explicit field to return value tracking 5 CLI flags
  • Updated thread.ts to read networkOpts.explicit.* instead of re-checking process.argv

Tests

  • test/provider/filter.test.ts — 6 unit tests: disabled-only, enabled-only, both, neither, empty enabled, overlap
  • test/cli/network.test.ts — 6 unit tests: CLI override, config fallback, defaults, mdns+hostname interaction, cors merge, explicit flags

All existing tests pass (987/995; 3 pre-existing failures in session-select.test.ts unrelated to these changes).

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/13703 **State:** open **Merged:** No --- ## Summary - Extract `Provider.filter(config)` function to eliminate repeated disabled/enabled provider filtering across 3 files - Add `explicit` flag tracking to `resolveNetworkOptions` return value, removing `process.argv.includes` duplication in `thread.ts` ## Motivation Provider filtering logic (Set creation from `disabled_providers`/`enabled_providers` + predicate check) was duplicated in: - `provider.ts` state() closure - `server/routes/provider.ts` route handler - `cli/cmd/auth.ts` auth flow Similarly, `thread.ts` re-checked `process.argv.includes("--port")` etc. after calling `resolveNetworkOptions` because the function didn't expose which flags were explicitly set. ## Changes ### Provider.filter extraction - Added `Provider.filter(config)` returning `{ disabled: Set, allowed(id): boolean }` - Updated `provider.ts` state() to use `pf.allowed()` for final filter and `pf.disabled.has()` for assembly guards - Replaced inline Set creation + filtering in `routes/provider.ts` and `auth.ts` - Standardized `null` (was inconsistent `null` vs `undefined`) for missing `enabled_providers` ### resolveNetworkOptions explicit flags - Extracted pure `resolveFrom(args, config, argv)` function for testability - Added `explicit` field to return value tracking 5 CLI flags - Updated `thread.ts` to read `networkOpts.explicit.*` instead of re-checking `process.argv` ## Tests - `test/provider/filter.test.ts` — 6 unit tests: disabled-only, enabled-only, both, neither, empty enabled, overlap - `test/cli/network.test.ts` — 6 unit tests: CLI override, config fallback, defaults, mdns+hostname interaction, cors merge, explicit flags All existing tests pass (987/995; 3 pre-existing failures in session-select.test.ts unrelated to these changes).
yindo added the pull-request label 2026-02-16 18:19:32 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#14781