• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

stacklok / codegate-ui / 13724706155

07 Mar 2025 04:14PM CUT coverage: 66.516% (-3.1%) from 69.62%
13724706155

Pull #355

github

web-flow
Merge 401ebe83b into db80e1ec2
Pull Request #355: [POC] feat: node-based muxing editor

424 of 711 branches covered (59.63%)

Branch coverage included in aggregate %.

22 of 89 new or added lines in 6 files covered. (24.72%)

81 existing lines in 4 files now uncovered.

903 of 1284 relevant lines covered (70.33%)

67.21 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

57.14
/src/lib/utils.ts
1
import { format } from 'date-fns'
2
import { AppConfig } from '@/global'
3

4
const FILEPATH_REGEX = /(?:---FILEPATH|Path:|\/\/\s*filepath:)\s*([^\s]+)/g
5✔
5
const COMPARE_CODE_REGEX = /Compare this snippet[^:]*:/g
5✔
6

7
function parsingByKeys(text: string | undefined, timestamp: string) {
8
  const fallback = `Prompt ${format(new Date(timestamp ?? ''), 'y/MM/dd - hh:mm:ss a')}`
14!
9
  try {
14✔
10
    if (!text) return fallback
14!
11
    const filePath = text.match(FILEPATH_REGEX)
14✔
12
    const compareCode = text.match(COMPARE_CODE_REGEX)
14✔
13
    // there some edge cases in copilot where the prompts are not correctly parsed. In this case is better to show the filepath
14
    if (compareCode || filePath) {
14!
15
      if (filePath)
×
UNCOV
16
        return `Prompt on file${filePath[0]?.trim().toLocaleLowerCase()}`
×
17

18
      if (compareCode)
×
UNCOV
19
        return `Prompt from snippet ${compareCode[0]?.trim().toLocaleLowerCase()}`
×
20
    }
21

22
    return text.trim()
14✔
23
  } catch {
UNCOV
24
    return fallback
×
25
  }
26
}
27

28
export function parsingPromptText(message: string, timestamp: string) {
29
  try {
14✔
30
    // checking malformed markdown code blocks
31
    const regex = /^(.*)```[\s\S]*?```(.*)$/s
14✔
32
    const match = message.match(regex)
14✔
33

34
    if (match !== null && match !== undefined) {
14!
35
      const beforeMarkdown = match[1]?.trim()
×
36
      const afterMarkdown = match[2]?.trim()
×
37
      const title = beforeMarkdown || afterMarkdown
×
UNCOV
38
      return parsingByKeys(title, timestamp)
×
39
    }
40

41
    return parsingByKeys(message, timestamp)
14✔
42
  } catch {
UNCOV
43
    return message.trim()
×
44
  }
45
}
46

47
export function sanitizeQuestionPrompt({
48
  question,
49
  answer,
50
}: {
51
  question: string
52
  answer: string
53
}) {
54
  try {
27✔
55
    // it shouldn't be possible to receive the prompt answer without a question
56
    if (!answer) {
27!
UNCOV
57
      throw new Error('Missing AI answer')
×
58
    }
59

60
    // Check if 'answer' is truthy; if so, try to find and return the text after "Query:"
61
    const index = question.indexOf('Query:')
27✔
62
    if (index !== -1) {
27!
63
      // Return the substring starting right after the first occurrence of "Query:"
64
      // Adding the length of "Query:" to the index to start after it
UNCOV
65
      return question.substring(index + 'Query:'.length).trim()
×
66
    }
67
    return question
27✔
68
  } catch (error) {
69
    // Log the error and return the original question as a fallback
70
    console.error('Error processing the question:', error)
×
UNCOV
71
    return question
×
72
  }
73
}
74

75
export function getAppConfig(): AppConfig {
76
  const baseApiUrl = window.APP_CONFIG?.DASHBOARD_API_BASE_URL
4✔
77

78
  if (!baseApiUrl || baseApiUrl === '${DASHBOARD_API_BASE_URL}') {
4✔
79
    return {
3✔
80
      ...window.APP_CONFIG,
81
      DASHBOARD_API_BASE_URL: import.meta.env.VITE_BASE_API_URL,
82
    }
83
  }
84

85
  return {
1✔
86
    ...window.APP_CONFIG,
87
    DASHBOARD_API_BASE_URL: baseApiUrl,
88
  }
89
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc