Skip to content

Commit accf518

Browse files
committed
code review fixes
1 parent 2d9b4fc commit accf518

3 files changed

Lines changed: 77 additions & 12 deletions

File tree

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import { describe, expect, it } from 'vitest'
2+
3+
import type { PrerequisiteCheckResult } from 'common'
4+
5+
import { getPrerequisiteSummary } from './prerequisite-summary.js'
6+
7+
const makeCheckResult = (
8+
prerequisiteId: string,
9+
status: PrerequisiteCheckResult['status'],
10+
): PrerequisiteCheckResult => ({
11+
prerequisiteId,
12+
status,
13+
output: '',
14+
checkedAt: '',
15+
})
16+
17+
describe('getPrerequisiteSummary', () => {
18+
it('should return null for empty prereqIds', () => {
19+
const result = getPrerequisiteSummary([], new Map())
20+
expect(result).toBeNull()
21+
})
22+
23+
it('should return all satisfied when every prereq is satisfied', () => {
24+
const map = new Map<string, PrerequisiteCheckResult>([
25+
['p1', makeCheckResult('p1', 'satisfied')],
26+
['p2', makeCheckResult('p2', 'satisfied')],
27+
])
28+
const result = getPrerequisiteSummary(['p1', 'p2'], map)
29+
expect(result).toEqual({ satisfiedCount: 2, failedCount: 0, total: 2 })
30+
})
31+
32+
it('should count failed prerequisites', () => {
33+
const map = new Map<string, PrerequisiteCheckResult>([
34+
['p1', makeCheckResult('p1', 'satisfied')],
35+
['p2', makeCheckResult('p2', 'failed')],
36+
['p3', makeCheckResult('p3', 'failed')],
37+
])
38+
const result = getPrerequisiteSummary(['p1', 'p2', 'p3'], map)
39+
expect(result).toEqual({ satisfiedCount: 1, failedCount: 2, total: 3 })
40+
})
41+
42+
it('should treat missing map entries as unchecked (neither satisfied nor failed)', () => {
43+
const map = new Map<string, PrerequisiteCheckResult>([['p1', makeCheckResult('p1', 'satisfied')]])
44+
const result = getPrerequisiteSummary(['p1', 'p2'], map)
45+
expect(result).toEqual({ satisfiedCount: 1, failedCount: 0, total: 2 })
46+
})
47+
48+
it('should treat "checking" and "unchecked" statuses as neither satisfied nor failed', () => {
49+
const map = new Map<string, PrerequisiteCheckResult>([
50+
['p1', makeCheckResult('p1', 'checking')],
51+
['p2', makeCheckResult('p2', 'unchecked')],
52+
['p3', makeCheckResult('p3', 'satisfied')],
53+
])
54+
const result = getPrerequisiteSummary(['p1', 'p2', 'p3'], map)
55+
expect(result).toEqual({ satisfiedCount: 1, failedCount: 0, total: 3 })
56+
})
57+
58+
it('should handle a mix of all statuses', () => {
59+
const map = new Map<string, PrerequisiteCheckResult>([
60+
['p1', makeCheckResult('p1', 'satisfied')],
61+
['p2', makeCheckResult('p2', 'failed')],
62+
['p3', makeCheckResult('p3', 'checking')],
63+
['p4', makeCheckResult('p4', 'unchecked')],
64+
])
65+
const result = getPrerequisiteSummary(['p1', 'p2', 'p3', 'p4', 'p5'], map)
66+
expect(result).toEqual({ satisfiedCount: 1, failedCount: 1, total: 5 })
67+
})
68+
})

service/src/services/process-manager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,6 @@ export class ProcessManager {
472472
}
473473

474474
public async [Symbol.asyncDispose]() {
475-
await this.runner[Symbol.asyncDispose]()
476-
477475
await this.logger.information({ message: 'Disposing ProcessManager, killing all child processes...' })
478476

479477
const entries = [...this.runner.processes.entries()]
@@ -523,6 +521,8 @@ export class ProcessManager {
523521
this.runner.processes.clear()
524522
}
525523

524+
await this.runner[Symbol.asyncDispose]()
525+
526526
try {
527527
await this.elevatedInjector?.[Symbol.asyncDispose]()
528528
} catch {

service/src/utils/secret-detector.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
export type SecretWarning = {
2-
line: number
3-
pattern: string
4-
snippet: string
5-
suggestion?: string
6-
}
1+
import type { SecretWarning } from 'common'
2+
3+
type SecretPatternMatch = Omit<SecretWarning, 'source'>
74

85
const SECRET_PATTERNS: Array<{ regex: RegExp; label: string }> = [
96
{ regex: /(?:password|passwd|pwd)\s*[=:]\s*\S+/i, label: 'password assignment' },
@@ -23,9 +20,9 @@ const MAX_SNIPPET_LENGTH = 80
2320
* Returns warnings with line numbers, the matched pattern name, and a
2421
* truncated snippet of the matching line.
2522
*/
26-
export const detectSecretPatterns = (text: string): SecretWarning[] => {
23+
export const detectSecretPatterns = (text: string): SecretPatternMatch[] => {
2724
const lines = text.split('\n')
28-
const warnings: SecretWarning[] = []
25+
const warnings: SecretPatternMatch[] = []
2926

3027
for (let i = 0; i < lines.length; i++) {
3128
const line = lines[i]
@@ -52,8 +49,8 @@ export const detectSecretsInServiceDefinition = (opts: {
5249
runCommand?: string
5350
installCommand?: string
5451
buildCommand?: string
55-
}): Array<SecretWarning & { source: string }> => {
56-
const results: Array<SecretWarning & { source: string }> = []
52+
}): SecretWarning[] => {
53+
const results: SecretWarning[] = []
5754

5855
for (const file of opts.files ?? []) {
5956
for (const warning of detectSecretPatterns(file.content)) {

0 commit comments

Comments
 (0)