mirror of
https://github.com/ZSeven-W/openpencil.git
synced 2026-05-31 19:04:29 +07:00
chore: enforce rust pre-commit checks
This commit is contained in:
parent
fa2d06c5af
commit
b6e9e91464
2 changed files with 26 additions and 63 deletions
|
|
@ -7,56 +7,35 @@
|
||||||
BRANCH=$(git rev-parse --abbrev-ref HEAD)
|
BRANCH=$(git rev-parse --abbrev-ref HEAD)
|
||||||
|
|
||||||
# Extract version from branch name like v0.5.0, v1.2.3, release/v2.0.0
|
# Extract version from branch name like v0.5.0, v1.2.3, release/v2.0.0
|
||||||
VERSION=$(echo "$BRANCH" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+')
|
VERSION=$(echo "$BRANCH" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+' || true)
|
||||||
|
|
||||||
if [ -z "$VERSION" ]; then
|
if [ -n "$VERSION" ]; then
|
||||||
exit 0
|
CHANGED=0
|
||||||
fi
|
for f in package.json apps/*/package.json packages/*/package.json; do
|
||||||
|
if [ -f "$f" ]; then
|
||||||
CHANGED=0
|
CURRENT=$(jq -r '.version' "$f")
|
||||||
for f in package.json apps/*/package.json packages/*/package.json; do
|
if [ "$CURRENT" != "$VERSION" ]; then
|
||||||
if [ -f "$f" ]; then
|
jq --arg v "$VERSION" '.version=$v' "$f" > "$f.tmp" && mv "$f.tmp" "$f"
|
||||||
CURRENT=$(jq -r '.version' "$f")
|
git add "$f"
|
||||||
if [ "$CURRENT" != "$VERSION" ]; then
|
CHANGED=1
|
||||||
jq --arg v "$VERSION" '.version=$v' "$f" > "$f.tmp" && mv "$f.tmp" "$f"
|
fi
|
||||||
git add "$f"
|
|
||||||
CHANGED=1
|
|
||||||
fi
|
fi
|
||||||
fi
|
done
|
||||||
done
|
|
||||||
|
|
||||||
if [ "$CHANGED" = "1" ]; then
|
if [ "$CHANGED" = "1" ]; then
|
||||||
echo "[version-sync] branch $BRANCH → $VERSION"
|
echo "[version-sync] branch $BRANCH → $VERSION"
|
||||||
fi
|
|
||||||
|
|
||||||
# --- Auto-format via the same script CI uses, then re-stage staged files ---
|
|
||||||
#
|
|
||||||
# Run `bun run format:check` first; if it fails, run `bun run format` to
|
|
||||||
# auto-fix and re-stage only the files that were already staged. New
|
|
||||||
# files added without going through the formatter (the most common cause
|
|
||||||
# of CI format-check failures) get fixed silently here. The format
|
|
||||||
# scripts already respect .prettierignore so the agent-native submodule
|
|
||||||
# and generated files are untouched.
|
|
||||||
#
|
|
||||||
# NOTE: re-adding files pulls in any unstaged hunks from a partially
|
|
||||||
# staged file. Stage cleanly if that matters to you.
|
|
||||||
if ! bun run format:check > /dev/null 2>&1; then
|
|
||||||
echo "[pre-commit] format drift detected — running \`bun run format\`"
|
|
||||||
if ! bun run format > /dev/null 2>&1; then
|
|
||||||
echo "[pre-commit] \`bun run format\` failed"; exit 1;
|
|
||||||
fi
|
|
||||||
STAGED=$(git diff --cached --name-only --diff-filter=d \
|
|
||||||
| grep -E '\.(ts|tsx|js|jsx|cjs|mjs|json|jsonc|md|yml|yaml)$' || true)
|
|
||||||
if [ -n "$STAGED" ]; then
|
|
||||||
echo "$STAGED" | xargs git add
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# --- Lint staged TS/JS files (no auto-fix, fail loudly on errors) ---
|
# --- Rust format + lint gates (same checks as CI) ---
|
||||||
LINT_STAGED=$(git diff --cached --name-only --diff-filter=d \
|
echo "[pre-commit] checking Rust format"
|
||||||
| grep -E '\.(ts|tsx|js|jsx|cjs|mjs)$' || true)
|
if ! cargo fmt --all -- --check; then
|
||||||
if [ -n "$LINT_STAGED" ]; then
|
echo "[pre-commit] Rust format check failed. Run: cargo fmt --all"
|
||||||
echo "$LINT_STAGED" | xargs npx oxlint || {
|
exit 1
|
||||||
echo "[pre-commit] lint failed. Run: bun run lint:fix"; exit 1;
|
fi
|
||||||
}
|
|
||||||
|
echo "[pre-commit] running Rust clippy"
|
||||||
|
if ! cargo clippy --workspace --all-targets -- -D warnings; then
|
||||||
|
echo "[pre-commit] Rust clippy failed. Fix warnings before committing."
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
|
||||||
|
|
@ -104,13 +104,6 @@ pub struct DesignPoll {
|
||||||
pub finished: bool,
|
pub finished: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DesignPoll {
|
|
||||||
#[cfg(test)]
|
|
||||||
fn is_idle(&self) -> bool {
|
|
||||||
self.progress.is_empty() && self.summary.is_none() && !self.finished
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl DesignSession {
|
impl DesignSession {
|
||||||
/// Spawn a worker that runs `Orchestrator::run` against a
|
/// Spawn a worker that runs `Orchestrator::run` against a
|
||||||
/// `RemoteDocSink`. Returns immediately; the LLM turn streams off
|
/// `RemoteDocSink`. Returns immediately; the LLM turn streams off
|
||||||
|
|
@ -202,21 +195,12 @@ impl DesignSession {
|
||||||
out
|
out
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Test-only accessor.
|
|
||||||
#[cfg(test)]
|
|
||||||
pub fn finished(&self) -> bool {
|
|
||||||
self.finished
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Test-only ctor — wraps externally-supplied channels so a fake
|
/// Test-only ctor — wraps externally-supplied channels so a fake
|
||||||
/// worker thread can drive the UI-side pumps end-to-end without
|
/// worker thread can drive the UI-side pumps end-to-end without
|
||||||
/// spinning up a real LLM. Production code goes through
|
/// spinning up a real LLM. Production code goes through
|
||||||
/// [`DesignSession::start`].
|
/// [`DesignSession::start`].
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub fn from_channels(
|
pub fn from_channels(delta_rx: Receiver<DesignDelta>, cmd_rx: Receiver<DesignCmdReq>) -> Self {
|
||||||
delta_rx: Receiver<DesignDelta>,
|
|
||||||
cmd_rx: Receiver<DesignCmdReq>,
|
|
||||||
) -> Self {
|
|
||||||
Self {
|
Self {
|
||||||
delta_rx,
|
delta_rx,
|
||||||
cmd_rx,
|
cmd_rx,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue