Skip to content

Commit

Permalink
Tests: revert environment loading and make hardware sed term posix co…
Browse files Browse the repository at this point in the history
…mplaint
  • Loading branch information
miklschmidt committed Feb 9, 2025
1 parent a53f8f4 commit fd1e3b3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
11 changes: 0 additions & 11 deletions src/.env.test

This file was deleted.

3 changes: 2 additions & 1 deletion src/server/helpers/file-operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { getLogger } from '@/server/helpers/logger';
import { loadEnvironment } from '@/server/helpers/utils';

export const getScriptRoot = () => {
return loadEnvironment().RATOS_SCRIPT_DIR;
// This is ... not great.. come up with something better
return process.env.RATOS_SCRIPT_DIR ?? __dirname.split('configurator/')[0] + 'configurator/scripts/';
};

/**
Expand Down
15 changes: 13 additions & 2 deletions src/server/helpers/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ import { MetadataCache, cacheAsyncMetadataFn, cacheMetadataFn } from '@/server/h
export const parseMetadata = async <T extends ZodType>(cfgFile: string, zod: T): Promise<z.infer<T> | null> => {
if (cfgFile.trim() === '') return null;

const hashmarkPrefixedJson = await promisify(exec)(`sed -n '/^# {/{:a; N; /\\n# }/!ba; p}' ${cfgFile}`);
const hashmarkPrefixedJson = await promisify(exec)(
`sed -n -e '/^# {/{:a' -e 'N' -e '/\\n# }/!ba' -e 'p' -e '}' ${cfgFile}`,
{
shell: '/bin/bash',
},
);
const jsonArray = hashmarkPrefixedJson.stdout
.split('\n')
.map((l) => l.trim())
Expand All @@ -43,7 +48,13 @@ export const parseMetadata = async <T extends ZodType>(cfgFile: string, zod: T):
if (e instanceof Error) {
getLogger().error(e.message);
}
throw new Error('Failed to parse JSON from file: ' + cfgFile + ' with content: ' + jsonArray.join('\n'));
throw new Error(
'Failed to parse JSON from file: ' +
cfgFile +
' with content: ' +
jsonArray.join('\n') +
(e && typeof e === 'object' && 'message' in e ? '\n' + e.message : ''),
);
}
};

Expand Down

0 comments on commit fd1e3b3

Please sign in to comment.