Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.git
node_modules
dist
coverage
.codegraph
68 changes: 68 additions & 0 deletions .github/workflows/auth-lock.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Auth lock portability

on:
pull_request:
paths:
- 'Dockerfile'
- '.dockerignore'
- 'scripts/mcp-smoke-test.mjs'
- 'src/auth/**'
- 'src/__tests__/auth-*'
- 'src/__tests__/fixtures/auth-worker.mjs'
- 'src/fs-native-extensions.d.ts'
- 'package*.json'
- '.github/workflows/auth-lock.yml'
push:
branches: [main]
paths:
- 'Dockerfile'
- '.dockerignore'
- 'scripts/mcp-smoke-test.mjs'
- 'src/auth/**'
- 'src/__tests__/auth-*'
- 'src/__tests__/fixtures/auth-worker.mjs'
- 'src/fs-native-extensions.d.ts'
- 'package*.json'
- '.github/workflows/auth-lock.yml'

permissions:
contents: read

jobs:
auth-lock:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
node: [20, 24]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v5
- uses: actions/setup-node@v5
with:
node-version: ${{ matrix.node }}
cache: npm
- run: npm ci
- run: npx jest src/__tests__/auth-multiprocess.test.ts --runInBand

docker:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- uses: actions/setup-node@v5
with:
node-version: 24
cache: npm
- run: npm ci
- run: npm test
- run: npm run build
- run: docker build -t mcp-linear:auth-lock .
- name: Verify native credential lock in the production image
run: >-
docker run --rm mcp-linear:auth-lock node --input-type=module -e
"import { withCredentialsLock } from './dist/auth/credential-store.js';
await withCredentialsLock(async () => {});"
- name: Verify MCP server in the production image
run: >-
docker run --rm -v "$PWD/scripts:/app/scripts:ro"
mcp-linear:auth-lock node scripts/mcp-smoke-test.mjs
30 changes: 7 additions & 23 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,33 +1,17 @@
# Generated by https://smithery.ai. See: https://smithery.ai/docs/config#dockerfile
FROM node:lts-alpine AS builder
FROM node:24-bookworm-slim AS builder

WORKDIR /app

# Copy package.json and package-lock.json if exists
COPY package.json ./

# Install dependencies without running scripts to avoid issues
RUN npm install --ignore-scripts

# Copy the rest of the files
COPY package.json package-lock.json ./
RUN npm ci --ignore-scripts
COPY . ./

# Build the project
RUN npm run build


FROM node:lts-alpine
FROM node:24-bookworm-slim

WORKDIR /app

# Copy only necessary files for runtime
COPY package.json ./
COPY package.json package-lock.json ./
RUN npm ci --omit=dev --ignore-scripts
COPY --from=builder /app/dist ./dist

# Install only production dependencies
RUN npm install --production --ignore-scripts

EXPOSE 3000

# Run the server
CMD ["npm", "start"]
CMD ["npm", "start"]
77 changes: 77 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"cors": "^2.8.5",
"dotenv": "^16.4.7",
"express": "^4.21.2",
"fs-native-extensions": "^1.5.3",
"graphql": "^16.10.0",
"graphql-request": "^7.1.2",
"helmet": "^8.0.0",
Expand Down
35 changes: 35 additions & 0 deletions src/__tests__/auth-credential-store.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ import path from 'node:path';
import {
deleteStoredCredentials,
getCredentialsPath,
getCredentialsLockPath,
readStoredCredentials,
writeStoredCredentials,
withCredentialsLock,
type StoredCredentials,
} from '../auth/credential-store.js';

Expand Down Expand Up @@ -122,3 +124,36 @@ describe('credential store', () => {
expect(deleteStoredCredentials()).toBe(false);
});
});

describe('credentials lock', () => {
const originalEnv = process.env;
let tempDir: string;

beforeEach(() => {
process.env = { ...originalEnv };
tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'mcp-linear-lock-'));
process.env.MCP_LINEAR_CONFIG_DIR = tempDir;
});

afterEach(() => {
process.env = originalEnv;
fs.rmSync(tempDir, { recursive: true, force: true });
});

it('does not take over a lock held by a live process just because it is old', async () => {
await withCredentialsLock(async () => {
const old = new Date(Date.now() - 120_000);
fs.utimesSync(getCredentialsLockPath(), old, old);
await expect(withCredentialsLock(async () => undefined, { retryMs: 5, timeoutMs: 50 }))
.rejects.toThrow(/Timed out/);
});
});

it('retains the lock file and releases it for the next holder', async () => {
await withCredentialsLock(async () => {
expect(fs.existsSync(getCredentialsLockPath())).toBe(true);
});
await expect(withCredentialsLock(async () => 'acquired')).resolves.toBe('acquired');
expect(fs.existsSync(getCredentialsLockPath())).toBe(true);
});
});
Loading
Loading