Skip to content

Commit 4eed231

Browse files
feat: use logExcerpt from output_files (#1829)
* fix: use logExcerpt from output_files Fixes a step on logsheet where the log_excerpt should be retrieved from the output_files field of a build/test Closes #1828 * tests: add unit tests for processLogData
1 parent f7b8318 commit 4eed231

6 files changed

Lines changed: 74 additions & 8 deletions

File tree

backend/kernelCI_app/models.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ class Builds(models.Model):
109109
architecture = models.TextField(blank=True, null=True)
110110
command = models.TextField(blank=True, null=True)
111111
compiler = models.TextField(blank=True, null=True)
112+
# input/output files are an array of objects containing file fields such as name and url
112113
input_files = models.JSONField(blank=True, null=True)
113114
output_files = models.JSONField(blank=True, null=True)
114115
config_name = models.TextField(blank=True, null=True)
@@ -170,6 +171,8 @@ class UnitPrefix(models.TextChoices):
170171
)
171172
start_time = models.DateTimeField(blank=True, null=True)
172173
duration = models.FloatField(blank=True, null=True)
174+
# input/output files are an array of objects containing file fields such as name and url
175+
input_files = models.JSONField(blank=True, null=True)
173176
output_files = models.JSONField(blank=True, null=True)
174177
misc = models.JSONField(blank=True, null=True)
175178
number_value = models.FloatField(blank=True, null=True)
@@ -178,7 +181,6 @@ class UnitPrefix(models.TextChoices):
178181
max_length=10, choices=UnitPrefix.choices, blank=True, null=True
179182
)
180183
number_unit = models.TextField(blank=True, null=True)
181-
input_files = models.JSONField(blank=True, null=True)
182184

183185
class Meta:
184186
db_table = "tests"
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { describe, expect, it } from 'vitest';
2+
3+
import { processLogData } from './useLogData';
4+
5+
describe('processLogData', () => {
6+
it('maps build fields and defaults status to NULL when missing', () => {
7+
const result = processLogData('build-1', {
8+
type: 'build',
9+
git_commit_name: 'Fix scheduler race',
10+
misc: { platform: 'qemu-x86' },
11+
output_files: [{ name: 'other_file', url: 'https://example.com/other' }],
12+
});
13+
14+
expect(result).toMatchObject({
15+
id: 'build-1',
16+
type: 'build',
17+
title: 'Fix scheduler race',
18+
status: 'NULL',
19+
hardware: 'qemu-x86',
20+
log_excerpt: undefined,
21+
});
22+
});
23+
24+
it('maps test fields and picks first hardware candidate from buildHardwareArray', () => {
25+
const result = processLogData('test-1', {
26+
type: 'test',
27+
path: 'boot/smoke',
28+
status: 'PASS',
29+
environment_misc: { platform: 'rk3399' },
30+
environment_compatible: ['arm64', 'lab-board'],
31+
});
32+
33+
expect(result).toMatchObject({
34+
id: 'test-1',
35+
type: 'test',
36+
title: 'boot/smoke',
37+
status: 'PASS',
38+
hardware: 'rk3399',
39+
});
40+
});
41+
42+
it('extracts log excerpt URL from output_files when present', () => {
43+
const result = processLogData('build-2', {
44+
type: 'build',
45+
status: 'FAIL',
46+
output_files: [
47+
{ name: 'artifact', url: 'https://example.com/artifact' },
48+
{ name: 'log_excerpt', url: 'https://example.com/log-excerpt' },
49+
],
50+
});
51+
52+
expect(result.log_excerpt).toBe('https://example.com/log-excerpt');
53+
});
54+
});

dashboard/src/hooks/useLogData.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ export const processLogData = (
5555
? data.misc.platform
5656
: undefined;
5757

58+
const logExcerptFileLink = data?.output_files?.find(
59+
file => file && file['name'] === 'log_excerpt',
60+
)?.['url'];
61+
5862
return {
5963
id,
6064
type: data.type,
@@ -65,7 +69,7 @@ export const processLogData = (
6569
git_repository_url: data?.git_repository_url,
6670
architecture: data?.architecture,
6771
log_url: data?.log_url,
68-
log_excerpt: data?.log_excerpt,
72+
log_excerpt: data?.log_excerpt || logExcerptFileLink,
6973
status: handledStatus,
7074
hardware: handledHardware,
7175
};

dashboard/src/types/database.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@ import type { status } from '@/utils/constants/database';
33
export type Status = (typeof status)[number];
44

55
export type InconclusiveStatus = Exclude<Status, 'PASS' | 'FAIL'>;
6+
7+
// Follows kcidb schema: https://github.com/kernelci/kcidb-io/blob/8971c0269a80307ec6270ff8c78ff3816fc639f6/kcidb_io/schema/v05_03.py#L62
8+
export type Resource = {
9+
name: string;
10+
url: string;
11+
};

dashboard/src/types/tree/BuildDetails.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Status } from '@/types/database';
1+
import type { Resource, Status } from '@/types/database';
22

33
export type TBuildDetails = {
44
timestamp: string;
@@ -24,6 +24,6 @@ export type TBuildDetails = {
2424
build_origin: string;
2525
log_excerpt?: string;
2626
misc?: Record<string, unknown>;
27-
input_files?: Record<string, unknown>;
28-
output_files?: Record<string, unknown>;
27+
input_files?: Resource[];
28+
output_files?: Resource[];
2929
};

dashboard/src/types/tree/TestDetails.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { Status } from '@/types/database';
1+
import type { Resource, Status } from '@/types/database';
22

33
export type TTestDetails = {
44
architecture?: string;
@@ -18,8 +18,8 @@ export type TTestDetails = {
1818
environment_compatible?: string[];
1919
environment_misc?: Record<string, unknown>;
2020
misc?: Record<string, unknown>;
21-
input_files?: Record<string, unknown>;
22-
output_files?: Record<string, unknown>;
21+
input_files?: Resource[];
22+
output_files?: Resource[];
2323
tree_name?: string;
2424
origin?: string;
2525
field_timestamp: string;

0 commit comments

Comments
 (0)