Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(app-shell-odd): overhaul odd system update #16486

Merged
merged 38 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
657cce0
refactor(app-shell-odd): move brightness
sfoster1 Oct 4, 2024
243deec
refactor(app-shell-odd): move update files
sfoster1 Oct 4, 2024
b4e9e6b
refactor(app-shell-odd): remove duplicate handler
sfoster1 Oct 7, 2024
f79d659
refactor(app-shell-odd): move update constants
sfoster1 Oct 7, 2024
9b538dc
refactor(app-shell-odd): remove little used file
sfoster1 Oct 7, 2024
763bf3f
refactor(app-shell-odd): add aborts to http
sfoster1 Oct 8, 2024
f640172
refactor(app-shell-odd): split updates into pieces
sfoster1 Oct 10, 2024
6d1dcf8
refactor: updates should include release note content
sfoster1 Oct 11, 2024
6c274a9
refactor(app-shell-odd): integrate providers
sfoster1 Oct 14, 2024
b0b3caf
lints
sfoster1 Oct 15, 2024
9d4ac41
test fixes for usb
sfoster1 Oct 15, 2024
6460aa7
obviously not
sfoster1 Oct 15, 2024
2e66605
How Embarassing
sfoster1 Oct 15, 2024
e4d50b4
fix: need shell so these are echoed
sfoster1 Oct 15, 2024
71ebd3c
fix: this name changed
sfoster1 Oct 15, 2024
5894dae
refactor: actually save stuff to disk
sfoster1 Oct 15, 2024
4737f7f
"ha ha"
sfoster1 Oct 15, 2024
029e4bf
refactor: fix log typing
sfoster1 Oct 15, 2024
7c4fba8
add some extra debug logs
sfoster1 Oct 15, 2024
ed3664f
refactor: set userdata earlier
sfoster1 Oct 16, 2024
5c029f7
refactor: some nicer logging
sfoster1 Oct 16, 2024
93898da
log typing fixups
sfoster1 Oct 16, 2024
d209c91
fix: fix up usb sensing named volumes
sfoster1 Oct 16, 2024
f211917
fix: fix up some usb logs
sfoster1 Oct 16, 2024
b84ef85
fix: fixup scan-usb
sfoster1 Oct 16, 2024
6b6b3ff
some extra logging
sfoster1 Oct 17, 2024
12cd94f
refactor: reflect redux messages to handlers
sfoster1 Oct 17, 2024
e93f6b4
fix: some usb enumeration bugs
sfoster1 Oct 17, 2024
1f2c373
some typing stuff
sfoster1 Oct 17, 2024
7d764f8
need some mocking
sfoster1 Oct 17, 2024
4e7b195
format and lint
sfoster1 Oct 17, 2024
f6d09b9
this type needs to be in app-shell too
sfoster1 Oct 17, 2024
213589e
absolutely not
sfoster1 Oct 17, 2024
c614113
fix: next-tickify dispatches
sfoster1 Oct 17, 2024
7617dca
Merge branch 'edge' into rqa-3060-overhaul-odd-system-update
sfoster1 Oct 18, 2024
99783da
the quick review feedback
sfoster1 Oct 21, 2024
7d055a8
comments
sfoster1 Oct 21, 2024
9507a74
dont need this anymore
sfoster1 Oct 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/workflows/app-test-build-deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,11 @@ jobs:
strategy:
matrix:
os: ['windows-2022', 'ubuntu-22.04', 'macos-latest']
name: 'opentrons app backend unit tests on ${{matrix.os}}'
shell: ['app-shell', 'app-shell-odd', 'discovery-client']
exclude:
- os: 'windows-2022'
shell: 'app-shell-odd'
name: 'opentrons ${{matrix.shell}} unit tests on ${{matrix.os}}'
timeout-minutes: 60
runs-on: ${{ matrix.os }}
steps:
Expand Down Expand Up @@ -144,7 +148,7 @@ jobs:
yarn config set cache-folder ${{ github.workspace }}/.yarn-cache
make setup-js
- name: 'test native(er) packages'
run: make test-js-internal tests="app-shell/src app-shell-odd/src discovery-client/src" cov_opts="--coverage=true"
run: make test-js-internal tests="${{}matrix.shell}/src" cov_opts="--coverage=true"
- name: 'Upload coverage report'
uses: 'codecov/codecov-action@v3'
with:
Expand Down
1 change: 1 addition & 0 deletions app-shell-odd/src/__tests__/http.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { Request, Response } from 'node-fetch'

vi.mock('../config')
vi.mock('node-fetch')
vi.mock('../log')

describe('app-shell main http module', () => {
beforeEach(() => {
Expand Down
47 changes: 0 additions & 47 deletions app-shell-odd/src/__tests__/update.test.ts

This file was deleted.

2 changes: 2 additions & 0 deletions app-shell-odd/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
export const configInitialized = (config: Config): ConfigInitializedAction => ({
type: CONFIG_INITIALIZED,
payload: { config },
meta: { shell: true },
})

// config value has been updated
Expand All @@ -128,6 +129,7 @@
): ConfigValueUpdatedAction => ({
type: VALUE_UPDATED,
payload: { path, value },
meta: { shell: true },
})

export const customLabwareList = (
Expand Down Expand Up @@ -355,7 +357,7 @@
export const appRestart = (message: string): AppRestartAction => ({
type: APP_RESTART,
payload: {
message: message,

Check warning on line 360 in app-shell-odd/src/actions.ts

View workflow job for this annotation

GitHub Actions / js checks

Expected property shorthand

Check warning on line 360 in app-shell-odd/src/actions.ts

View workflow job for this annotation

GitHub Actions / js checks

Expected property shorthand
},
meta: { shell: true },
})
Expand All @@ -363,7 +365,7 @@
export const reloadUi = (message: string): ReloadUiAction => ({
type: RELOAD_UI,
payload: {
message: message,

Check warning on line 368 in app-shell-odd/src/actions.ts

View workflow job for this annotation

GitHub Actions / js checks

Expected property shorthand

Check warning on line 368 in app-shell-odd/src/actions.ts

View workflow job for this annotation

GitHub Actions / js checks

Expected property shorthand
},
meta: { shell: true },
})
Expand All @@ -371,7 +373,7 @@
export const sendLog = (message: string): SendLogAction => ({
type: SEND_LOG,
payload: {
message: message,

Check warning on line 376 in app-shell-odd/src/actions.ts

View workflow job for this annotation

GitHub Actions / js checks

Expected property shorthand

Check warning on line 376 in app-shell-odd/src/actions.ts

View workflow job for this annotation

GitHub Actions / js checks

Expected property shorthand
},
meta: { shell: true },
})
Expand All @@ -379,7 +381,7 @@
export const updateBrightness = (message: string): UpdateBrightnessAction => ({
type: UPDATE_BRIGHTNESS,
payload: {
message: message,

Check warning on line 384 in app-shell-odd/src/actions.ts

View workflow job for this annotation

GitHub Actions / js checks

Expected property shorthand

Check warning on line 384 in app-shell-odd/src/actions.ts

View workflow job for this annotation

GitHub Actions / js checks

Expected property shorthand
},
meta: { shell: true },
})
Expand Down
16 changes: 10 additions & 6 deletions app-shell-odd/src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import get from 'lodash/get'
import forEach from 'lodash/forEach'
import mergeOptions from 'merge-options'
import yargsParser from 'yargs-parser'

import { UI_INITIALIZED } from '../constants'
import * as Cfg from '../constants'
import { configInitialized, configValueUpdated } from '../actions'
import systemd from '../systemd'
import { createLogger } from '../log'
import { DEFAULTS_V12, migrate } from './migrate'
import { shouldUpdate, getNextValue } from './update'
import { setUserDataPath } from '../early'

import type {
ConfigV12,
Expand All @@ -24,8 +24,6 @@ import type { Config, Overrides } from './types'

export * from './types'

export const ODD_DIR = '/data/ODD'

// make sure all arguments are included in production
const argv = process.argv0.endsWith('defaultApp')
? process.argv.slice(2)
Expand All @@ -48,8 +46,7 @@ const store = (): Store => {
// perform store migration if loading for the first time
_store = (new Store({
defaults: DEFAULTS_V12,
// dont overwrite config dir if in dev mode because it causes issues
...(process.env.NODE_ENV === 'production' && { cwd: ODD_DIR }),
cwd: setUserDataPath(),
}) as unknown) as Store<Config>
_store.store = migrate((_store.store as unknown) as ConfigV12)
}
Expand All @@ -66,7 +63,14 @@ const log = (): Logger => _log ?? (_log = createLogger('config'))
export function registerConfig(dispatch: Dispatch): (action: Action) => void {
return function handleIncomingAction(action: Action) {
if (action.type === UI_INITIALIZED) {
log().info('initializing configuration')
dispatch(configInitialized(getFullConfig()))
log().info(
`flow route: ${
getConfig('onDeviceDisplaySettings').unfinishedUnboxingFlowRoute
}`
)
log().info('configuration initialized')
} else if (
action.type === Cfg.UPDATE_VALUE ||
action.type === Cfg.RESET_VALUE ||
Expand Down Expand Up @@ -120,8 +124,8 @@ export function getOverrides(path?: string): unknown {
return path != null ? get(overrides(), path) : overrides()
}

export function getConfig<P extends keyof Config>(path: P): Config[P]
export function getConfig(): Config
export function getConfig<P extends keyof Config>(path: P): Config[P]
export function getConfig(path?: any): any {
const result = store().get(path)
const over = getOverrides(path as string | undefined)
Expand Down
2 changes: 2 additions & 0 deletions app-shell-odd/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,3 +257,5 @@ export const FAILURE_STATUSES = {
} as const

export const SEND_FILE_PATHS: 'shell:SEND_FILE_PATHS' = 'shell:SEND_FILE_PATHS'

export const ODD_DATA_DIR = '/data/ODD'
22 changes: 22 additions & 0 deletions app-shell-odd/src/early.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// things intended to execute early in app-shell initialization
// do as little as possible in this file and do none of it at import time

import { app } from 'electron'
import { ODD_DATA_DIR } from './constants'

let path: string

export const setUserDataPath = (): string => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we care to split out get and set functions?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I could call this getEnsuredUserDataPath or something?

if (path == null) {
console.log(
`node env is ${process.env.NODE_ENV}, path is ${app.getPath('userData')}`
)
if (process.env.NODE_ENV === 'production') {
console.log(`setting app path to ${ODD_DATA_DIR}`)
app.setPath('userData', ODD_DATA_DIR)
}
path = app.getPath('userData')
console.log(`app path becomes ${app.getPath('userData')}`)
}
return app.getPath('userData')
}
52 changes: 43 additions & 9 deletions app-shell-odd/src/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,30 @@ import FormData from 'form-data'
import { Transform } from 'stream'

import { HTTP_API_VERSION } from './constants'
import { createLogger } from './log'

import type { Readable } from 'stream'
import type { Request, RequestInit, Response } from 'node-fetch'

const log = createLogger('http')

type RequestInput = Request | string

export interface DownloadProgress {
downloaded: number
size: number | null
}

export class LocalAbortError extends Error {
declare readonly name: 'LocalAbortError'
declare readonly type: 'aborted'
constructor(message: string) {
super(message)
this.name = 'LocalAbortError'
this.type = 'aborted'
}
}

export function fetch(
input: RequestInput,
init?: RequestInit
Expand All @@ -35,21 +48,29 @@ export function fetch(
})
}

export function fetchJson<Body>(input: RequestInput): Promise<Body> {
return fetch(input).then(response => response.json())
export function fetchJson<Body>(
input: RequestInput,
init?: RequestInit
): Promise<Body> {
return fetch(input, init).then(response => response.json())
}

export function fetchText(input: Request, init?: RequestInit): Promise<string> {
return fetch(input, init).then(response => response.text())
}

export function fetchText(input: Request): Promise<string> {
return fetch(input).then(response => response.text())
export interface FetchToFileOptions {
onProgress: (progress: DownloadProgress) => unknown
signal: AbortSignal
}

// TODO(mc, 2019-07-02): break this function up and test its components
export function fetchToFile(
input: RequestInput,
destination: string,
options?: Partial<{ onProgress: (progress: DownloadProgress) => unknown }>
options?: Partial<FetchToFileOptions>
): Promise<string> {
return fetch(input).then(response => {
return fetch(input, { signal: options?.signal }).then(response => {
let downloaded = 0
const size = Number(response.headers.get('Content-Length')) || null

Expand All @@ -75,13 +96,26 @@ export function fetchToFile(
// pump calls stream.pipe, handles teardown if streams error, and calls
// its callbacks when the streams are done
pump(inputStream, progressReader, outputStream, error => {
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
if (error) {
const handleError = (problem: Error): void => {
// if we error out, delete the temp dir to clean up
return remove(destination).then(() => {
log.error(`Aborting fetchToFile: ${problem.name}: ${problem.message}`)
remove(destination).then(() => {
reject(error)
})
}
const listener = (): void => {
handleError(
new LocalAbortError(
(options?.signal?.reason as string | null) ?? 'aborted'
)
)
}
options?.signal?.addEventListener('abort', listener, { once: true })
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
if (error) {
handleError(error)
}
options?.signal?.removeEventListener('abort', listener, {})
resolve(destination)
})
})
Expand Down
4 changes: 2 additions & 2 deletions app-shell-odd/src/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import path from 'path'
import dateFormat from 'dateformat'
import winston from 'winston'

import { setUserDataPath } from './early'
import { getConfig } from './config'

import type Transport from 'winston-transport'
import type { Config } from './config'

const ODD_DIR = '/data/ODD'
const LOG_DIR = path.join(ODD_DIR, 'logs')
const LOG_DIR = path.join(setUserDataPath(), 'logs')
const ERROR_LOG = path.join(LOG_DIR, 'error.log')
const COMBINED_LOG = path.join(LOG_DIR, 'combined.log')

Expand Down
Loading
Loading