Skip to content

Commit d5ab04b

Browse files
committed
fix: normalize nested css selectors and simplify runtime probe parsing
1 parent 0300d56 commit d5ab04b

2 files changed

Lines changed: 57 additions & 18 deletions

File tree

dashboard/vite.config.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,30 @@ import { defineConfig } from 'vite';
33
import vue from '@vitejs/plugin-vue';
44
import vuetify from 'vite-plugin-vuetify';
55

6+
const normalizeNestedTypeSelectorPlugin = {
7+
postcssPlugin: 'normalize-nested-type-selector',
8+
Rule(rule: { parent?: { type?: string }; selector?: string }) {
9+
if (rule.parent?.type !== 'rule' || typeof rule.selector !== 'string') {
10+
return;
11+
}
12+
13+
const segments = rule.selector
14+
.split(',')
15+
.map((segment) => segment.trim())
16+
.filter(Boolean);
17+
if (!segments.length) {
18+
return;
19+
}
20+
21+
const typeOnlyPattern = /^[a-zA-Z][\w-]*$/;
22+
if (!segments.every((segment) => typeOnlyPattern.test(segment))) {
23+
return;
24+
}
25+
26+
rule.selector = segments.map((segment) => `:is(${segment})`).join(', ');
27+
}
28+
};
29+
630
// https://vitejs.dev/config/
731
export default defineConfig({
832
plugins: [
@@ -24,6 +48,9 @@ export default defineConfig({
2448
}
2549
},
2650
css: {
51+
postcss: {
52+
plugins: [normalizeNestedTypeSelectorPlugin]
53+
},
2754
preprocessorOptions: {
2855
scss: {}
2956
}

desktop/scripts/runtime-version-utils.mjs

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -168,11 +168,7 @@ export const resolveExpectedRuntimeVersion = ({ rootDir }) => {
168168
);
169169
};
170170

171-
export const validateRuntimePython = ({
172-
pythonExecutable,
173-
expectedRuntimeConstraint,
174-
requirePipProbe,
175-
}) => {
171+
const runPythonProbe = ({ pythonExecutable, requirePipProbe }) => {
176172
const probeScript = requirePipProbe
177173
? 'import sys, pip; print(sys.version_info[0], sys.version_info[1])'
178174
: 'import sys; print(sys.version_info[0], sys.version_info[1])';
@@ -193,30 +189,46 @@ export const validateRuntimePython = ({
193189

194190
if (probe.status !== 0) {
195191
const stderrText = (probe.stderr || '').trim();
196-
if (requirePipProbe) {
197-
throw new Error(
198-
`Runtime Python probe failed with exit code ${probe.status}. ` +
199-
`pip import check is enabled by ASTRBOT_DESKTOP_REQUIRE_PIP=1. ` +
200-
(stderrText ? `stderr: ${stderrText}` : ''),
201-
);
202-
}
203192
throw new Error(
204193
`Runtime Python probe failed with exit code ${probe.status}. ` +
194+
(requirePipProbe ? 'pip import check is enabled by ASTRBOT_DESKTOP_REQUIRE_PIP=1. ' : '') +
205195
(stderrText ? `stderr: ${stderrText}` : ''),
206196
);
207197
}
208198

209-
const parts = (probe.stdout || '').trim().split(/\s+/);
199+
return probe.stdout || '';
200+
};
201+
202+
const parseProbeVersion = (stdoutText) => {
203+
const trimmedOutput = String(stdoutText || '').trim();
204+
const parts = trimmedOutput.split(/\s+/);
210205
if (parts.length < 2) {
211206
throw new Error(
212-
`Runtime Python probe did not report a valid version. Output: ${(probe.stdout || '').trim()}`,
207+
`Runtime Python probe did not report a valid version. Output: ${trimmedOutput}`,
213208
);
214209
}
215210

216-
const actualVersion = {
217-
major: Number.parseInt(parts[0], 10),
218-
minor: Number.parseInt(parts[1], 10),
219-
};
211+
const major = Number.parseInt(parts[0], 10);
212+
const minor = Number.parseInt(parts[1], 10);
213+
if (!Number.isInteger(major) || !Number.isInteger(minor)) {
214+
throw new Error(
215+
`Runtime Python probe did not report a valid version. Output: ${trimmedOutput}`,
216+
);
217+
}
218+
219+
return { major, minor };
220+
};
221+
222+
export const validateRuntimePython = ({
223+
pythonExecutable,
224+
expectedRuntimeConstraint,
225+
requirePipProbe,
226+
}) => {
227+
const probeOutput = runPythonProbe({
228+
pythonExecutable,
229+
requirePipProbe,
230+
});
231+
const actualVersion = parseProbeVersion(probeOutput);
220232
const expectedRuntimeVersion = expectedRuntimeConstraint.expectedRuntimeVersion;
221233
const compareResult = compareMajorMinor(actualVersion, expectedRuntimeVersion);
222234
if (expectedRuntimeConstraint.isLowerBoundRuntimeVersion) {

0 commit comments

Comments
 (0)