Skip to content

Commit 6472cee

Browse files
authored
[v5] Let a suite's schema name its default branch (#679)
Part of #671.
1 parent b7e542b commit 6472cee

35 files changed

Lines changed: 667 additions & 137 deletions

‎docs/convert_v4_mirror.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ The target suite's schema is derived from the v4 schema and the suite's
5656
machines:
5757

5858
- **Display name**: none, since v4 has no notion of one.
59+
- **Default branch**: none, since v4 has no notion of branches.
5960
- **Metrics**: one per v4 metric, with the same name. ``Real`` becomes ``real``,
6061
``Status`` becomes ``integer``, and ``Hash`` becomes ``text``; any other type
6162
is an error. ``bigger_is_better``, ``unit`` and ``unit_abbrev`` are kept,

‎lnt/util/convert_v4_mirror.py‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,10 +340,11 @@ def _derive_schema(mirrored: MirroredSuite, target_suite: str,
340340
'searchable': False, 'listed': name in declared}
341341
for name in declared + undeclared]
342342

343-
# v4 knows nothing of the repository the commits come from.
343+
# v4 knows nothing of the repository the commits come from, nor of
344+
# branches.
344345
schema = {'name': target_suite, 'display_name': None,
345-
'metrics': metrics, 'machine_fields': machine_fields,
346-
'commit_fields': [],
346+
'default_branch': None, 'metrics': metrics,
347+
'machine_fields': machine_fields, 'commit_fields': [],
347348
'repository': {'label': None, 'commit_url': None,
348349
'range_url': None}}
349350
check_schema(schema, problems)

‎tests/lnttool/convert-v4-mirror.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ def dump(value):
139139
# declared machine fields are listed.
140140
# CHECK-LABEL: # CONVERSION
141141
# CHECK: "commit_fields": [],
142+
# CHECK-NEXT: "default_branch": null,
142143
# CHECK-NEXT: "display_name": null,
143144
# CHECK-NEXT: "machine_fields": [
144145
# CHECK-NEXT: {

‎v5/client/src/api/client.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { TOKEN, mockAuth, unknownToken } from '../test/auth'
88
const SUITE = {
99
name: 'nts',
1010
display_name: null,
11+
default_branch: null,
1112
metrics: [],
1213
commit_fields: [],
1314
machine_fields: [],

‎v5/client/src/api/schema.d.ts‎

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ export interface paths {
314314
/**
315315
* Change a test suite's schema
316316
* @description Add, update, remove or reorder metrics, commit fields and machine fields, or change the
317-
* display name or the repository. Returns the updated schema.
317+
* display name, the default branch or the repository. Returns the updated schema.
318318
*
319319
* Only display settings can be updated. To change the type of a metric or field, remove it and
320320
* add it again. Removing a metric or field permanently deletes its data, so the request must
@@ -2459,6 +2459,7 @@ export interface components {
24592459
* "type": "text"
24602460
* }
24612461
* ],
2462+
* "default_branch": "main",
24622463
* "display_name": "Microbenchmarks",
24632464
* "machine_fields": [
24642465
* {
@@ -3240,23 +3241,28 @@ export interface components {
32403241
};
32413242
/**
32423243
* SchemaPatch
3243-
* @description Changes to a suite's display name, metrics, commit fields, machine fields and repository.
3244-
* What you leave out is not changed.
3244+
* @description Changes to a suite's display name, default branch, metrics, commit fields, machine fields and
3245+
* repository. What you leave out is not changed.
32453246
*
32463247
* Either all the changes are applied or none are, and the resulting schema must be valid. Each
32473248
* metric or field can only be added, updated or removed once per request, and a list's new
32483249
* `order` comes after those changes. New metrics and fields go at the end of their list, in the
32493250
* order given, and have no value for existing data. Removing one permanently deletes its data
32503251
* (and, for a metric, the regression indicators that refer to it), so the request must include
32513252
* `confirm=true`. To rename a metric or field, remove it and add it again. Changing the display
3252-
* name, the repository or an order needs no confirmation.
3253+
* name, the default branch, the repository or an order needs no confirmation.
32533254
*/
32543255
SchemaPatch: {
32553256
/**
32563257
* Display Name
32573258
* @description How the web UI names the suite, instead of its `name`. At most 256 characters. Only the name addresses the suite in the API. Null removes it.
32583259
*/
32593260
display_name?: string | null;
3261+
/**
3262+
* Default Branch
3263+
* @description The suite's default branch, such as `main`, a hint for the web UI. A branch name, as a commit's `branch` is: 1 to 256 characters. The server does not check that any commit is on it. Null removes it.
3264+
*/
3265+
default_branch?: string | null;
32603266
metrics?: components["schemas"]["MetricChanges"];
32613267
commit_fields?: components["schemas"]["CommitFieldChanges"];
32623268
machine_fields?: components["schemas"]["MachineFieldChanges"];
@@ -3275,9 +3281,9 @@ export interface components {
32753281
};
32763282
/**
32773283
* SuiteSchema
3278-
* @description A test suite's schema: its name and display name, the metrics, commit fields and machine
3279-
* fields it defines, and the repository its commits come from. A suite can only store what its
3280-
* schema defines.
3284+
* @description A test suite's schema: its name, display name and default branch, the metrics, commit fields
3285+
* and machine fields it defines, and the repository its commits come from. A suite can only store
3286+
* what its schema defines.
32813287
*
32823288
* The same document is used to create a suite and is returned when reading one (with all
32833289
* optional keys filled in), so a suite read from one instance can be created as-is on another.
@@ -3300,6 +3306,7 @@ export interface components {
33003306
* "type": "text"
33013307
* }
33023308
* ],
3309+
* "default_branch": "main",
33033310
* "display_name": "Microbenchmarks",
33043311
* "machine_fields": [
33053312
* {
@@ -3404,6 +3411,11 @@ export interface components {
34043411
* @description How the web UI names the suite, instead of its `name`. At most 256 characters. Only the name addresses the suite in the API. Null if there is none.
34053412
*/
34063413
display_name: string | null;
3414+
/**
3415+
* Default Branch
3416+
* @description The suite's default branch, such as `main`, a hint for the web UI. A branch name, as a commit's `branch` is: 1 to 256 characters. The server does not check that any commit is on it. Null if there is none.
3417+
*/
3418+
default_branch: string | null;
34073419
/**
34083420
* Metrics
34093421
* @description What the suite's tests measure.
@@ -3424,9 +3436,9 @@ export interface components {
34243436
};
34253437
/**
34263438
* SuiteSchemaInput
3427-
* @description A test suite's schema: its name and display name, the metrics, commit fields and machine
3428-
* fields it defines, and the repository its commits come from. A suite can only store what its
3429-
* schema defines.
3439+
* @description A test suite's schema: its name, display name and default branch, the metrics, commit fields
3440+
* and machine fields it defines, and the repository its commits come from. A suite can only store
3441+
* what its schema defines.
34303442
*
34313443
* The same document is used to create a suite and is returned when reading one (with all
34323444
* optional keys filled in), so a suite read from one instance can be created as-is on another.
@@ -3449,6 +3461,7 @@ export interface components {
34493461
* "type": "text"
34503462
* }
34513463
* ],
3464+
* "default_branch": "main",
34523465
* "display_name": "Microbenchmarks",
34533466
* "machine_fields": [
34543467
* {
@@ -3553,6 +3566,11 @@ export interface components {
35533566
* @description How the web UI names the suite, instead of its `name`. At most 256 characters. Only the name addresses the suite in the API. Null if there is none.
35543567
*/
35553568
display_name?: string | null;
3569+
/**
3570+
* Default Branch
3571+
* @description The suite's default branch, such as `main`, a hint for the web UI. A branch name, as a commit's `branch` is: 1 to 256 characters. The server does not check that any commit is on it. Null if there is none.
3572+
*/
3573+
default_branch?: string | null;
35563574
/**
35573575
* Metrics
35583576
* @description What the suite's tests measure.

‎v5/client/src/pages/admin/create-suite.test.tsx‎

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ function mockCreate(
5151
const body = JSON.parse(text) as Partial<SuiteSchema> & { name: string }
5252
const schema: SuiteSchema = {
5353
display_name: null,
54+
default_branch: null,
5455
metrics: [],
5556
commit_fields: [],
5657
machine_fields: [],
@@ -83,6 +84,10 @@ function displayNameInput() {
8384
return screen.getByRole('textbox', { name: 'Display name' })
8485
}
8586

87+
function defaultBranchInput() {
88+
return screen.getByRole('textbox', { name: 'Default branch' })
89+
}
90+
8691
function createButton() {
8792
return screen.getByRole('button', { name: /^(Create|Creating\.\.\.)$/ })
8893
}
@@ -282,7 +287,7 @@ describe('opening the editor', () => {
282287
expect(confirm).not.toHaveBeenCalled()
283288
})
284289

285-
it('has unsaved changes once a name, an entry or a repository value is entered', async () => {
290+
it('has unsaved changes once a name, a default branch, an entry or a repository value is entered', async () => {
286291
await openEditor()
287292

288293
typeInto(displayNameInput(), ' ')
@@ -291,6 +296,12 @@ describe('opening the editor', () => {
291296
expect(unloadAsks()).toBe(true)
292297
typeInto(displayNameInput(), '')
293298

299+
typeInto(defaultBranchInput(), ' ')
300+
expect(unloadAsks()).toBe(false)
301+
typeInto(defaultBranchInput(), 'main')
302+
expect(unloadAsks()).toBe(true)
303+
typeInto(defaultBranchInput(), '')
304+
294305
typeInto(screen.getByRole('textbox', { name: 'Range URL' }), ' ')
295306
expect(unloadAsks()).toBe(false)
296307
typeInto(screen.getByRole('textbox', { name: 'Range URL' }), 'h')
@@ -540,6 +551,7 @@ describe('creating the suite', () => {
540551
const confirm = answerLeaving(false)
541552
typeInto(suiteNameInput(), 'fresh')
542553
typeInto(screen.getByRole('textbox', { name: 'Display name' }), ' Fresh suite ')
554+
typeInto(defaultBranchInput(), ' main ')
543555
addEntry('metric', 'size')
544556
await pickOption('Type of metric size', 'integer')
545557
typeInto(screen.getByRole('textbox', { name: 'Display name of metric size' }), ' Size ')
@@ -556,6 +568,7 @@ describe('creating the suite', () => {
556568
expect(JSON.parse(sent[0].text)).toEqual({
557569
name: 'fresh',
558570
display_name: 'Fresh suite',
571+
default_branch: 'main',
559572
metrics: [
560573
{
561574
name: 'size',
@@ -577,7 +590,7 @@ describe('creating the suite', () => {
577590
expect(confirm).not.toHaveBeenCalled()
578591
expect(editor()).not.toBeInTheDocument()
579592
expect(await screen.findByRole('group', { name: 'Suite' })).toHaveTextContent(
580-
'ProjectllvmNamefreshDisplay nameFresh suite',
593+
'ProjectllvmNamefreshDisplay nameFresh suiteDefault branchmain',
581594
)
582595
expect(rowsOf(await table('Metrics'))).toEqual(['size | integer | Size | -- | Yes | Yes'])
583596
expect(rowsOf(await table('Machine fields'))).toEqual(['kernel | text | -- | No | No'])
@@ -602,6 +615,7 @@ describe('creating the suite', () => {
602615
expect(JSON.parse(sent[0].text)).toEqual({
603616
name: 'empty',
604617
display_name: null,
618+
default_branch: null,
605619
metrics: [],
606620
commit_fields: [],
607621
machine_fields: [],
@@ -860,6 +874,17 @@ describe('Start from', () => {
860874
).toEqual(['execution_time'])
861875
})
862876

877+
it("replaces the default branch with the suite's, clearing it when the suite has none", async () => {
878+
await openEditor({ suites: [{ ...SUITE, default_branch: 'main' }, BARE_SUITE] })
879+
typeInto(defaultBranchInput(), 'mine')
880+
881+
await pickSuite('Start from', 'llvm', 'libcxx')
882+
expect(defaultBranchInput()).toHaveValue('main')
883+
884+
await pickSuite('Start from', 'llvm', 'nts')
885+
expect(defaultBranchInput()).toHaveValue('')
886+
})
887+
863888
it('changes nothing from the keyboard while its list is closed', async () => {
864889
await openEditor()
865890
const user = userEvent.setup()

‎v5/client/src/pages/admin/create-suite.tsx‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { ErrorMessage } from '../../components/feedback'
1919
import { Select } from '../../components/select'
2020
import { useUnsavedChanges } from '../../components/use-unsaved-changes'
2121
import {
22+
changeDefaultBranch,
2223
copyOf,
2324
EMPTY_DRAFT,
2425
draftProblem,
@@ -40,9 +41,9 @@ interface Props {
4041
}
4142

4243
/**
43-
* The schema editor creating a suite (TS7) in the project `project`: the suite's name, its entries
44-
* and its repository, which can start as a copy of another suite's. Or, through "Import JSON", a
45-
* schema document sent as it is.
44+
* The schema editor creating a suite (TS7) in the project `project`: the suite's name, its entries,
45+
* its repository and its default branch, the last three of which can start as a copy of another
46+
* suite's. Or, through "Import JSON", a schema document sent as it is.
4647
*/
4748
export function CreateSuite({ project, onCancel, onCreated }: Props) {
4849
const { status } = useAuth()
@@ -142,8 +143,8 @@ export function CreateSuite({ project, onCancel, onCreated }: Props) {
142143
/>
143144
) : (
144145
<>
145-
{/* A form, so that Enter in the suite's name or display name creates the suite. Its
146-
submit button is Create, below the tables. */}
146+
{/* A form, so that Enter in the suite's name, display name or default branch creates the
147+
suite. Its submit button is Create, below the tables. */}
147148
<form id={formId} aria-labelledby={titleId} onSubmit={submit}>
148149
<SuiteFields
149150
project={projectLabel(projectNamed(list, project))}
@@ -153,6 +154,10 @@ export function CreateSuite({ project, onCancel, onCreated }: Props) {
153154
nameRef={nameRef}
154155
displayName={displayName}
155156
onDisplayName={setDisplayName}
157+
defaultBranch={draft.default_branch.text}
158+
onDefaultBranch={(text) => {
159+
if (!busy) setDraft((current) => changeDefaultBranch(current, text))
160+
}}
156161
readOnly={busy}
157162
/>
158163
</form>

‎v5/client/src/pages/test-suites/schema-tab.test.tsx‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ vi.mock('./schema/download', () => ({ downloadFile: vi.fn() }))
4545
const UNITLESS: Suite = inProject({
4646
name: 'units',
4747
display_name: null,
48+
default_branch: null,
4849
metrics: [
4950
{
5051
name: 'neither',
@@ -204,9 +205,10 @@ describe('the Schema tab', () => {
204205
'Machine Fields',
205206
'Repository',
206207
])
207-
// The suite by its project's label, its name, and its display name, which it has none of.
208+
// The suite by its project's label, its name, and its display name and default branch, which
209+
// it has none of.
208210
expect(screen.getByRole('group', { name: 'Suite' })).toHaveTextContent(
209-
'Project' + 'llvm' + 'Name' + 'libcxx' + 'Display name' + '--',
211+
'Project' + 'llvm' + 'Name' + 'libcxx' + 'Display name' + '--' + 'Default branch' + '--',
210212
)
211213
// The templates as text, not links: they are not URLs until filled in.
212214
const repository = screen.getByRole('group', { name: 'Repository' })
@@ -221,14 +223,22 @@ describe('the Schema tab', () => {
221223
expect(within(repository).queryByRole('link')).toBeNull()
222224
})
223225

224-
it("shows the suite's project by its label, and the suite's display name", async () => {
226+
it("shows the suite's project by its label, and the suite's display name and default branch", async () => {
225227
const project = { name: 'llvm', display_name: 'LLVM' }
226-
mockSuites([inProject({ ...SUITE, display_name: 'Microbenchmarks' }, project)])
228+
const suite = { ...SUITE, display_name: 'Microbenchmarks', default_branch: 'main' }
229+
mockSuites([inProject(suite, project)])
227230
renderPage('/projects/llvm/suites/libcxx?tab=schema')
228231

229232
await table('Metrics')
230233
expect(screen.getByRole('group', { name: 'Suite' })).toHaveTextContent(
231-
'Project' + 'LLVM' + 'Name' + 'libcxx' + 'Display name' + 'Microbenchmarks',
234+
'Project' +
235+
'LLVM' +
236+
'Name' +
237+
'libcxx' +
238+
'Display name' +
239+
'Microbenchmarks' +
240+
'Default branch' +
241+
'main',
232242
)
233243
})
234244

0 commit comments

Comments
 (0)