Files
coder/site/e2e/api.ts
T
Jeremy Ruppel c9cb02a55c chore: enable oxlint no-explicit-any and disable the Biome equivalent (#28733)
Promotes the oxlint `no-explicit-any` rule from the migration backlog to
`error` and disables Biome's analogous `suspicious/noExplicitAny`, so
oxlint becomes the sole enforcer of this rule.

The eight existing `biome-ignore lint/suspicious/noExplicitAny`
suppressions are removed and their `as any` casts replaced with precise
types (no `any`, no `as unknown as` double-casts):

- `optionValue.ts`: the default branch now asserts to the `OptionValue`
children union.
- `MonacoEditor.tsx`: a typed intersection describes Monaco's private
`_standaloneKeybindingService`.
- `e2e/helpers.ts`: a `BrowserContext` intersection types the
symbol-keyed current user.
- `e2e/api.ts`: `opt.value` (typed `unknown`) is asserted directly to
`string` / `string[]` / `Record<string, string>`.

`pnpm run lint` (Biome, oxlint, tsc, circular-deps, compiler, knip) and
`pnpm run format` pass clean.

<details>
<summary>Implementation plan</summary>

## Goal

Enable the oxlint rule `no-explicit-any` (mapped to Biome
`suspicious/noExplicitAny`), disable the analogous Biome rule, and fix
all resulting violations by removing the explicit `any` types (not by
migrating suppression comments).

## Findings

- The oxlint rule was parked in the migration backlog:
`"no-explicit-any": "off", // suspicious/noExplicitAny`.
- Running oxlint with the rule as error surfaced exactly 8 violations,
all in places already carrying `// biome-ignore
lint/suspicious/noExplicitAny` comments:
  - `src/pages/DeploymentSettingsPage/optionValue.ts` (1)
  - `src/pages/TemplateVersionEditorPage/MonacoEditor.tsx` (1)
  - `e2e/helpers.ts` (3)
  - `e2e/api.ts` (3)
- Biome's `noExplicitAny` is a recommended rule (implicitly on);
disabling it means adding an explicit `"off"` in the root `biome.jsonc`.
- `e2e/**` is type-checked by `lint:types` (`tsc -p .`), so e2e fixes
must type-check.

## Constraints

- Remove the `biome-ignore` comments and fix the `any`s (do not migrate
suppressions).
- Do not cast through `unknown` (no `x as unknown as Y`). Single direct
assertions from an already-`unknown` value and subtype intersection
casts are used instead.

## Changes

1. `site/.oxlintrc.jsonc`: move `no-explicit-any` to the active
suspicious section as `"error"`; drop the backlog entry.
2. `biome.jsonc`: add `"noExplicitAny": "off"` under
`linter.rules.suspicious`.
3. Fix the 8 violation sites and remove the 8 `biome-ignore` comments
across the 4 source files.

## Validation

- `pnpm run lint:oxlint` → 0 errors
- `pnpm run lint:check` (Biome) → clean
- `pnpm run lint:types` (`tsc -p .`) → clean (covers `src` and `e2e`)
- `optionValue.test.ts` → 16 tests pass
- full `pnpm run lint` and `pnpm run format` → clean

</details>

---

Generated by Coder Agents on behalf of @jeremyruppel.
2026-08-27 17:06:59 -04:00

313 lines
7.6 KiB
TypeScript

import type { Page } from "@playwright/test";
import { expect } from "@playwright/test";
import dayjs from "dayjs";
import duration from "dayjs/plugin/duration";
import relativeTime from "dayjs/plugin/relativeTime";
import { API, type DeploymentConfig } from "#/api/api";
import type { SerpentOption } from "#/api/typesGenerated";
dayjs.extend(duration);
dayjs.extend(relativeTime);
import { humanDuration } from "#/utils/time";
import { coderPort, defaultPassword } from "./constants";
import { findSessionToken, type LoginOptions, randomName } from "./helpers";
let currentOrgId: string;
export const setupApiCalls = async (page: Page) => {
API.setHost(`http://127.0.0.1:${coderPort}`);
const token = await findSessionToken(page);
API.setSessionToken(token);
};
export const getCurrentOrgId = async (): Promise<string> => {
if (currentOrgId) {
return currentOrgId;
}
const currentUser = await API.getAuthenticatedUser();
currentOrgId = currentUser.organization_ids[0];
return currentOrgId;
};
export const createUser = async (...orgIds: string[]) => {
const name = randomName();
const user = await API.createUser({
email: `${name}@coder.com`,
username: name,
name: name,
password: defaultPassword,
login_type: "password",
organization_ids: orgIds,
user_status: null,
});
return user;
};
type CreateOrganizationMemberOptions = {
username?: string;
email?: string;
password?: string;
orgRoles: Record<string, string[]>;
};
export const createOrganizationMember = async ({
username = randomName(),
email = `${username}@coder.com`,
password = defaultPassword,
orgRoles,
}: CreateOrganizationMemberOptions): Promise<LoginOptions> => {
const _name = randomName();
const user = await API.createUser({
email,
username,
name: username,
password,
login_type: "password",
organization_ids: Object.keys(orgRoles),
user_status: null,
});
for (const [org, roles] of Object.entries(orgRoles)) {
API.updateOrganizationMemberRoles(org, user.id, roles);
}
return {
username: user.username,
email: user.email,
password,
};
};
export const createGroup = async (orgId: string) => {
const name = randomName();
const group = await API.createGroup(orgId, {
name,
display_name: `Display ${name}`,
avatar_url: "/emojis/1f60d.png",
quota_allowance: 0,
});
return group;
};
export const createOrganization = async (name = randomName()) => {
const org = await API.createOrganization({
name,
display_name: `Org ${name}`,
description: `Org description ${name}`,
icon: "/emojis/1f957.png",
});
return org;
};
export const deleteOrganization = async (orgName: string) => {
await API.deleteOrganization(orgName);
};
export const createOrganizationWithName = async (name: string) => {
const org = await API.createOrganization({
name,
display_name: `${name}`,
description: `Org description ${name}`,
icon: "/emojis/1f957.png",
});
return org;
};
export const createOrganizationSyncSettings = async () => {
const settings = await API.patchOrganizationIdpSyncSettings({
field: "organization-field-test",
mapping: {
"idp-org-1": [
"fbd2116a-8961-4954-87ae-e4575bd29ce0",
"13de3eb4-9b4f-49e7-b0f8-0c3728a0d2e2",
],
"idp-org-2": ["6b39f0f1-6ad8-4981-b2fc-d52aef53ff1b"],
},
organization_assign_default: true,
});
return settings;
};
export const createGroupSyncSettings = async (orgId: string) => {
const settings = await API.patchGroupIdpSyncSettings(
{
field: "group-field-test",
mapping: {
"idp-group-1": [
"fbd2116a-8961-4954-87ae-e4575bd29ce0",
"13de3eb4-9b4f-49e7-b0f8-0c3728a0d2e2",
],
"idp-group-2": ["6b39f0f1-6ad8-4981-b2fc-d52aef53ff1b"],
},
regex_filter: "@[a-zA-Z0-9]+",
auto_create_missing_groups: true,
},
orgId,
);
return settings;
};
export const createRoleSyncSettings = async (orgId: string) => {
const settings = await API.patchRoleIdpSyncSettings(
{
field: "role-field-test",
mapping: {
"idp-role-1": [
"fbd2116a-8961-4954-87ae-e4575bd29ce0",
"13de3eb4-9b4f-49e7-b0f8-0c3728a0d2e2",
],
"idp-role-2": ["6b39f0f1-6ad8-4981-b2fc-d52aef53ff1b"],
},
},
orgId,
);
return settings;
};
export const createCustomRole = async (
orgId: string,
name: string,
displayName: string,
) => {
const role = await API.createOrganizationRole(orgId, {
name,
display_name: displayName,
organization_id: orgId,
site_permissions: [],
organization_permissions: [
{
negate: false,
resource_type: "organization_member",
action: "create",
},
{
negate: false,
resource_type: "organization_member",
action: "delete",
},
{
negate: false,
resource_type: "organization_member",
action: "read",
},
{
negate: false,
resource_type: "organization_member",
action: "update",
},
],
user_permissions: [],
organization_member_permissions: [],
});
return role;
};
export async function verifyConfigFlagBoolean(
page: Page,
config: DeploymentConfig,
flag: string,
) {
const opt = findConfigOption(config, flag);
const type = opt.value ? "option-enabled" : "option-disabled";
const value = opt.value ? "Enabled" : "Disabled";
const configOption = page.locator(
`table.options-table .option-${flag} .${type}`,
);
await expect(configOption).toHaveText(value);
}
export async function verifyConfigFlagNumber(
page: Page,
config: DeploymentConfig,
flag: string,
) {
const opt = findConfigOption(config, flag);
const configOption = page.locator(
`table.options-table .option-${flag} .option-value-number`,
);
await expect(configOption).toHaveText(String(opt.value));
}
export async function verifyConfigFlagString(
page: Page,
config: DeploymentConfig,
flag: string,
) {
const opt = findConfigOption(config, flag);
const configOption = page.locator(
`table.options-table .option-${flag} .option-value-string`,
);
await expect(configOption).toHaveText(opt.value as string);
}
export async function verifyConfigFlagArray(
page: Page,
config: DeploymentConfig,
flag: string,
) {
const opt = findConfigOption(config, flag);
const configOption = page.locator(
`table.options-table .option-${flag} .option-array`,
);
// Verify array of options with simple dots
for (const item of opt.value as string[]) {
await expect(configOption.locator("li", { hasText: item })).toBeVisible();
}
}
export async function verifyConfigFlagEntries(
page: Page,
config: DeploymentConfig,
flag: string,
) {
const opt = findConfigOption(config, flag);
const configOption = page.locator(
`table.options-table .option-${flag} .option-array`,
);
// Verify array of options with green marks.
Object.entries(opt.value as Record<string, string>)
.sort((a, b) => a[0].localeCompare(b[0]))
.map(async ([item]) => {
await expect(
configOption.locator(`.option-array-item-${item}.option-enabled`, {
hasText: item,
}),
).toBeVisible();
});
}
export async function verifyConfigFlagDuration(
page: Page,
config: DeploymentConfig,
flag: string,
) {
const opt = findConfigOption(config, flag);
if (typeof opt.value !== "number") {
throw new Error(
`Option with env ${flag} should be a number, but got ${typeof opt.value}.`,
);
}
const configOption = page.locator(
`table.options-table .option-${flag} .option-value-string`,
);
await expect(configOption).toHaveText(humanDuration(opt.value / 1e6));
}
export function findConfigOption(
config: DeploymentConfig,
flag: string,
): SerpentOption {
const opt = config.options.find((option) => option.flag === flag);
if (opt === undefined) {
// must be undefined as `false` is expected
throw new Error(`Option with env ${flag} has undefined value.`);
}
return opt;
}