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
12 changes: 8 additions & 4 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
* text=auto eof=lf
* text=auto eol=lf

################################################################################
# The following files are binary and should be left untouched.
Expand All @@ -25,7 +25,6 @@
cfn-init binary
*.node binary
*.wasm binary
*.bat binary

# Documents
*.pdf binary
Expand All @@ -36,7 +35,6 @@ cfn-init binary
*.ppt binary
*.pptx binary
*.odt binary
*.csv binary

# Images
*.png binary
Expand All @@ -48,7 +46,6 @@ cfn-init binary
*.tif binary
*.tiff binary
*.webp binary
*.svg binary

# Audio & Video
*.mp3 binary
Expand All @@ -63,3 +60,10 @@ cfn-init binary
*.jks binary
*.db binary
*.sqlite binary

# Windows batch files must always use CRLF, or they may fail to execute.
*.bat text eol=crlf
*.cmd text eol=crlf

# PowerShell can handle LF, but CRLF is safer for Windows-specific scripts
*.ps1 text eol=crlf
2 changes: 0 additions & 2 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,9 @@ jobs:
run: npm run build

- name: Code Quality
if: runner.os != 'Windows'
run: npm run lint && npm run check:duplicates

- name: Test
if: runner.os != 'Windows'
run: npm run test

build-test-go:
Expand Down
9 changes: 4 additions & 5 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ jobs:
pr-build-test-nodejs:
needs: [ get-configs ]
strategy:
fail-fast: true
fail-fast: false
matrix:
os: [ ubuntu-latest, macos-latest ]
os: [ ubuntu-latest, macos-latest, windows-latest ]
runs-on: ${{ matrix.os }}
permissions:
contents: read
Expand All @@ -35,7 +35,6 @@ jobs:
run: npm run build

- name: Code Quality
if: runner.os != 'Windows'
run: npm run lint && npm run check:duplicates

- name: Test
Expand All @@ -44,9 +43,9 @@ jobs:
pr-build-test-go:
needs: [ get-configs ]
strategy:
fail-fast: true
fail-fast: false
matrix:
os: [ ubuntu-latest, macos-latest ]
os: [ ubuntu-latest, macos-latest, windows-latest ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v5
Expand Down
4 changes: 2 additions & 2 deletions src/utils/ErrorStackInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ export function determineSensitiveInfo(): string[] {
errorStackInfo = __dirname
.replaceAll('\\\\', '/')
.replaceAll('\\', '/')
.split('/')
.split(/[/:]/)
.map((x) => {
return x.trim();
})
.filter((x) => {
return x.length > 0;
return x.length > 1;
});
} catch (err) {
LoggerFactory.getLogger('SensitiveInfo').warn(err, 'Cannot get __dirname');
Expand Down
58 changes: 22 additions & 36 deletions tst/unit/artifactexporter/ArtifactExporter.test.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import { existsSync, statSync, mkdtempSync, copyFileSync } from 'fs';
import { tmpdir } from 'os';
import { join, basename, extname } from 'path';
import { join } from 'path';
import { pathToFileURL } from 'url';
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { ArtifactExporter } from '../../../src/artifactexporter/ArtifactExporter';
import { DocumentType } from '../../../src/document/Document';
import { S3Service } from '../../../src/services/S3Service';

vi.mock('../../../src/services/S3Service');
vi.mock('fs');
vi.mock('os');
vi.mock('path');
vi.mock('archiver');

const FIXTURES_DIR = join(__dirname, '..', '..', 'resources', 'templates', 'artifact');

describe('ArtifactExporter', () => {
let mockS3Service: S3Service;
const templatePath = `file:///${join(__dirname, 'template.yaml')}`;
const templatePath = pathToFileURL(join(FIXTURES_DIR, 'template.yaml')).href;

const BASIC_TEMPLATE = 'Resources:\n Bucket:\n Type: AWS::S3::Bucket';

Expand All @@ -23,7 +20,7 @@ Resources:
MyFunction:
Type: AWS::Lambda::Function
Properties:
Code: ./src/lambda
Code: ./code
Runtime: nodejs18.x
Handler: index.handler
FunctionName: MyTestFunction
Expand Down Expand Up @@ -62,22 +59,6 @@ Resources:
putObjectContent: vi.fn(),
putObject: vi.fn().mockResolvedValue({ VersionId: 'v123' }),
} as any;

vi.mocked(existsSync).mockReturnValue(true);
vi.mocked(statSync).mockReturnValue({
isFile: () => true,
isDirectory: () => false,
} as any);
vi.mocked(tmpdir).mockReturnValue('/tmp');
vi.mocked(join).mockImplementation((...args) => args.join('/'));
vi.mocked(basename).mockImplementation((path) => path?.split('/').pop() ?? '');
vi.mocked(extname).mockImplementation((path) => {
if (!path) return '';
const parts = path.split('.');
return parts.length > 1 ? '.' + parts[parts.length - 1] : '';
});
vi.mocked(mkdtempSync).mockReturnValue('/tmp/cfn-123');
vi.mocked(copyFileSync).mockImplementation(() => {});
});

describe('getTemplateArtifacts', () => {
Expand All @@ -88,7 +69,7 @@ Resources:
expect(artifacts).toEqual([
{
resourceType: 'AWS::Lambda::Function',
filePath: './src/lambda',
filePath: './code',
},
]);
});
Expand All @@ -111,7 +92,7 @@ Resources:
const template = new ArtifactExporter(
mockS3Service,
DocumentType.YAML,
`file:///${join(__dirname, 'path/to/template.yaml')}`,
pathToFileURL(join(FIXTURES_DIR, 'path/to/template.yaml')).href,
BASIC_TEMPLATE,
);
expect(template).toBeDefined();
Expand All @@ -121,7 +102,7 @@ Resources:
const template = new ArtifactExporter(
mockS3Service,
DocumentType.YAML,
`file:///${join(__dirname, 'path/to/template.yaml')}`,
pathToFileURL(join(FIXTURES_DIR, 'path/to/template.yaml')).href,
BASIC_TEMPLATE,
);
const result = await template.export('test-bucket');
Expand All @@ -133,10 +114,15 @@ Resources:

const result = await exporter.export('test-bucket');

expect(mockS3Service.putObject).toHaveBeenCalledWith(
expect.stringMatching(/\.zip$/),
expect.stringMatching(/^s3:\/\/test-bucket\/artifact\/.*\.zip$/),
);

const resources = (result as any).Resources;
expect(resources.MyFunction.Properties.Code).toEqual({
S3Bucket: 'test-bucket',
S3Key: expect.stringMatching(/^artifact\/cfn-123-\d+$/),
S3Key: expect.stringMatching(/^artifact\/.*\.zip$/),
S3ObjectVersion: 'v123',
});
expect(resources.MyFunction.Properties.Runtime).toBe('nodejs18.x');
Expand All @@ -147,17 +133,17 @@ Resources:
});

it('should update Serverless function CodeUri to S3 URL', async () => {
const exporter = new ArtifactExporter(
mockS3Service,
DocumentType.YAML,
`file:///${join(__dirname, 'template.yaml')}`,
SERVERLESS_TEMPLATE,
);
const exporter = new ArtifactExporter(mockS3Service, DocumentType.YAML, templatePath, SERVERLESS_TEMPLATE);

const result = await exporter.export('my-bucket');

expect(mockS3Service.putObject).toHaveBeenCalledWith(
expect.stringMatching(/\.zip$/),
expect.stringMatching(/^s3:\/\/my-bucket\/artifact\/.*\.zip$/),
);

const resources = (result as any).Resources;
expect(resources.MyFunction.Properties.CodeUri).toMatch(/^s3:\/\/my-bucket\/artifact\/cfn-123-\d+$/);
expect(resources.MyFunction.Properties.CodeUri).toMatch(/^s3:\/\/my-bucket\/artifact\/.*\.zip$/);
expect(resources.MyFunction.Properties.Runtime).toBe('python3.9');
expect(resources.MyFunction.Properties.Handler).toBe('app.lambda_handler');
expect(resources.MyFunction.Properties.Description).toBe('Test serverless function');
Expand Down
2 changes: 1 addition & 1 deletion tst/unit/services/cfnLint/PyodideWorkerManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,7 @@ describe('PyodideWorkerManager', () => {
});

// Expect initialization to fail with timeout error
await expect(retryWorkerManager.initialize()).rejects.toThrow(/Pyodide initialization timed out after 3/);
await expect(retryWorkerManager.initialize()).rejects.toThrow(/Pyodide initialization timed out after/);

const totalTime = Date.now() - startTime;

Expand Down
8 changes: 4 additions & 4 deletions vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ export default defineConfig({
include: ['src/**/*.{js,ts}'],
enabled: true,
thresholds: {
statements: 85,
branches: 85,
functions: 85,
lines: 85,
statements: 88,
branches: 88,
functions: 88,
lines: 88,
},
exclude: [
'src/ai/**',
Expand Down
Loading