Skip to content

Commit 07946be

Browse files
authored
Fix windows build and tests (#352)
1 parent 48778df commit 07946be

File tree

7 files changed

+41
-54
lines changed

7 files changed

+41
-54
lines changed

.gitattributes

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
* text=auto eof=lf
1+
* text=auto eol=lf
22

33
################################################################################
44
# The following files are binary and should be left untouched.
@@ -25,7 +25,6 @@
2525
cfn-init binary
2626
*.node binary
2727
*.wasm binary
28-
*.bat binary
2928

3029
# Documents
3130
*.pdf binary
@@ -36,7 +35,6 @@ cfn-init binary
3635
*.ppt binary
3736
*.pptx binary
3837
*.odt binary
39-
*.csv binary
4038

4139
# Images
4240
*.png binary
@@ -48,7 +46,6 @@ cfn-init binary
4846
*.tif binary
4947
*.tiff binary
5048
*.webp binary
51-
*.svg binary
5249

5350
# Audio & Video
5451
*.mp3 binary
@@ -63,3 +60,10 @@ cfn-init binary
6360
*.jks binary
6461
*.db binary
6562
*.sqlite binary
63+
64+
# Windows batch files must always use CRLF, or they may fail to execute.
65+
*.bat text eol=crlf
66+
*.cmd text eol=crlf
67+
68+
# PowerShell can handle LF, but CRLF is safer for Windows-specific scripts
69+
*.ps1 text eol=crlf

.github/workflows/build-and-test.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,9 @@ jobs:
5858
run: npm run build
5959

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

6463
- name: Test
65-
if: runner.os != 'Windows'
6664
run: npm run test
6765

6866
build-test-go:

.github/workflows/pr.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ jobs:
1212
pr-build-test-nodejs:
1313
needs: [ get-configs ]
1414
strategy:
15-
fail-fast: true
15+
fail-fast: false
1616
matrix:
17-
os: [ ubuntu-latest, macos-latest ]
17+
os: [ ubuntu-latest, macos-latest, windows-latest ]
1818
runs-on: ${{ matrix.os }}
1919
permissions:
2020
contents: read
@@ -35,7 +35,6 @@ jobs:
3535
run: npm run build
3636

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

4140
- name: Test
@@ -44,9 +43,9 @@ jobs:
4443
pr-build-test-go:
4544
needs: [ get-configs ]
4645
strategy:
47-
fail-fast: true
46+
fail-fast: false
4847
matrix:
49-
os: [ ubuntu-latest, macos-latest ]
48+
os: [ ubuntu-latest, macos-latest, windows-latest ]
5049
runs-on: ${{ matrix.os }}
5150
steps:
5251
- uses: actions/checkout@v5

src/utils/ErrorStackInfo.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ export function determineSensitiveInfo(): string[] {
1212
errorStackInfo = __dirname
1313
.replaceAll('\\\\', '/')
1414
.replaceAll('\\', '/')
15-
.split('/')
15+
.split(/[/:]/)
1616
.map((x) => {
1717
return x.trim();
1818
})
1919
.filter((x) => {
20-
return x.length > 0;
20+
return x.length > 1;
2121
});
2222
} catch (err) {
2323
LoggerFactory.getLogger('SensitiveInfo').warn(err, 'Cannot get __dirname');

tst/unit/artifactexporter/ArtifactExporter.test.ts

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
1-
import { existsSync, statSync, mkdtempSync, copyFileSync } from 'fs';
2-
import { tmpdir } from 'os';
3-
import { join, basename, extname } from 'path';
1+
import { join } from 'path';
2+
import { pathToFileURL } from 'url';
43
import { describe, it, expect, vi, beforeEach } from 'vitest';
54
import { ArtifactExporter } from '../../../src/artifactexporter/ArtifactExporter';
65
import { DocumentType } from '../../../src/document/Document';
76
import { S3Service } from '../../../src/services/S3Service';
87

98
vi.mock('../../../src/services/S3Service');
10-
vi.mock('fs');
11-
vi.mock('os');
12-
vi.mock('path');
13-
vi.mock('archiver');
9+
10+
const FIXTURES_DIR = join(__dirname, '..', '..', 'resources', 'templates', 'artifact');
1411

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

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

@@ -23,7 +20,7 @@ Resources:
2320
MyFunction:
2421
Type: AWS::Lambda::Function
2522
Properties:
26-
Code: ./src/lambda
23+
Code: ./code
2724
Runtime: nodejs18.x
2825
Handler: index.handler
2926
FunctionName: MyTestFunction
@@ -62,22 +59,6 @@ Resources:
6259
putObjectContent: vi.fn(),
6360
putObject: vi.fn().mockResolvedValue({ VersionId: 'v123' }),
6461
} as any;
65-
66-
vi.mocked(existsSync).mockReturnValue(true);
67-
vi.mocked(statSync).mockReturnValue({
68-
isFile: () => true,
69-
isDirectory: () => false,
70-
} as any);
71-
vi.mocked(tmpdir).mockReturnValue('/tmp');
72-
vi.mocked(join).mockImplementation((...args) => args.join('/'));
73-
vi.mocked(basename).mockImplementation((path) => path?.split('/').pop() ?? '');
74-
vi.mocked(extname).mockImplementation((path) => {
75-
if (!path) return '';
76-
const parts = path.split('.');
77-
return parts.length > 1 ? '.' + parts[parts.length - 1] : '';
78-
});
79-
vi.mocked(mkdtempSync).mockReturnValue('/tmp/cfn-123');
80-
vi.mocked(copyFileSync).mockImplementation(() => {});
8162
});
8263

8364
describe('getTemplateArtifacts', () => {
@@ -88,7 +69,7 @@ Resources:
8869
expect(artifacts).toEqual([
8970
{
9071
resourceType: 'AWS::Lambda::Function',
91-
filePath: './src/lambda',
72+
filePath: './code',
9273
},
9374
]);
9475
});
@@ -111,7 +92,7 @@ Resources:
11192
const template = new ArtifactExporter(
11293
mockS3Service,
11394
DocumentType.YAML,
114-
`file:///${join(__dirname, 'path/to/template.yaml')}`,
95+
pathToFileURL(join(FIXTURES_DIR, 'path/to/template.yaml')).href,
11596
BASIC_TEMPLATE,
11697
);
11798
expect(template).toBeDefined();
@@ -121,7 +102,7 @@ Resources:
121102
const template = new ArtifactExporter(
122103
mockS3Service,
123104
DocumentType.YAML,
124-
`file:///${join(__dirname, 'path/to/template.yaml')}`,
105+
pathToFileURL(join(FIXTURES_DIR, 'path/to/template.yaml')).href,
125106
BASIC_TEMPLATE,
126107
);
127108
const result = await template.export('test-bucket');
@@ -133,10 +114,15 @@ Resources:
133114

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

117+
expect(mockS3Service.putObject).toHaveBeenCalledWith(
118+
expect.stringMatching(/\.zip$/),
119+
expect.stringMatching(/^s3:\/\/test-bucket\/artifact\/.*\.zip$/),
120+
);
121+
136122
const resources = (result as any).Resources;
137123
expect(resources.MyFunction.Properties.Code).toEqual({
138124
S3Bucket: 'test-bucket',
139-
S3Key: expect.stringMatching(/^artifact\/cfn-123-\d+$/),
125+
S3Key: expect.stringMatching(/^artifact\/.*\.zip$/),
140126
S3ObjectVersion: 'v123',
141127
});
142128
expect(resources.MyFunction.Properties.Runtime).toBe('nodejs18.x');
@@ -147,17 +133,17 @@ Resources:
147133
});
148134

149135
it('should update Serverless function CodeUri to S3 URL', async () => {
150-
const exporter = new ArtifactExporter(
151-
mockS3Service,
152-
DocumentType.YAML,
153-
`file:///${join(__dirname, 'template.yaml')}`,
154-
SERVERLESS_TEMPLATE,
155-
);
136+
const exporter = new ArtifactExporter(mockS3Service, DocumentType.YAML, templatePath, SERVERLESS_TEMPLATE);
156137

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

140+
expect(mockS3Service.putObject).toHaveBeenCalledWith(
141+
expect.stringMatching(/\.zip$/),
142+
expect.stringMatching(/^s3:\/\/my-bucket\/artifact\/.*\.zip$/),
143+
);
144+
159145
const resources = (result as any).Resources;
160-
expect(resources.MyFunction.Properties.CodeUri).toMatch(/^s3:\/\/my-bucket\/artifact\/cfn-123-\d+$/);
146+
expect(resources.MyFunction.Properties.CodeUri).toMatch(/^s3:\/\/my-bucket\/artifact\/.*\.zip$/);
161147
expect(resources.MyFunction.Properties.Runtime).toBe('python3.9');
162148
expect(resources.MyFunction.Properties.Handler).toBe('app.lambda_handler');
163149
expect(resources.MyFunction.Properties.Description).toBe('Test serverless function');

tst/unit/services/cfnLint/PyodideWorkerManager.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -925,7 +925,7 @@ describe('PyodideWorkerManager', () => {
925925
});
926926

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

930930
const totalTime = Date.now() - startTime;
931931

vitest.config.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ export default defineConfig({
1313
include: ['src/**/*.{js,ts}'],
1414
enabled: true,
1515
thresholds: {
16-
statements: 85,
17-
branches: 85,
18-
functions: 85,
19-
lines: 85,
16+
statements: 88,
17+
branches: 88,
18+
functions: 88,
19+
lines: 88,
2020
},
2121
exclude: [
2222
'src/ai/**',

0 commit comments

Comments
 (0)