Skip to content

Commit cfe92cd

Browse files
abbesBenayachePierreJeanjacquot
authored andcommitted
refactor: change result.txt to result.json and improve error messages
- Change output file extension from .txt to .json for better semantic accuracy - Rename 'dataset' field to 'protected-data' in bulk processing results - Improve error messages with 'Cause:' prefix and use 'protected-data' terminology - Update all tests to match new structure and file extensions
1 parent 17d041b commit cfe92cd

File tree

6 files changed

+53
-29
lines changed

6 files changed

+53
-29
lines changed

dapp/src/executeTask.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ async function start() {
116116
: `dataset-${index}.txt`,
117117
response: {
118118
status: 500,
119-
message: `Failed to process dataset ${index}: ${error.message}`,
119+
message: `Failed to process protected-data ${index}. Cause: ${error.message}`,
120120
},
121121
};
122122
});
@@ -127,7 +127,7 @@ async function start() {
127127
const bulkResults = await Promise.all(promises);
128128
results.push(...bulkResults);
129129

130-
// Write result.txt for bulk processing
130+
// Write result.json for bulk processing
131131
const successCount = results.filter(
132132
(r) => r.response.status === 200
133133
).length;
@@ -140,15 +140,15 @@ async function start() {
140140
'error-count': errorCount,
141141
results: results.map((r) => ({
142142
index: r.index,
143-
dataset:
143+
'protected-data':
144144
process.env[`IEXEC_DATASET_${r.index}_FILENAME`] ||
145145
`dataset-${r.index}`,
146146
response: r.response,
147147
})),
148148
};
149149

150150
await writeTaskOutput(
151-
`${workerEnv.IEXEC_OUT}/result.txt`,
151+
`${workerEnv.IEXEC_OUT}/result.json`,
152152
JSON.stringify(bulkResult, null, 2)
153153
);
154154
} else {
@@ -163,7 +163,7 @@ async function start() {
163163
results.push(result);
164164

165165
await writeTaskOutput(
166-
`${workerEnv.IEXEC_OUT}/result.txt`,
166+
`${workerEnv.IEXEC_OUT}/result.json`,
167167
JSON.stringify(result.response, null, 2)
168168
);
169169
}
@@ -173,7 +173,7 @@ async function start() {
173173
`${workerEnv.IEXEC_OUT}/computed.json`,
174174
JSON.stringify(
175175
{
176-
'deterministic-output-path': `${workerEnv.IEXEC_OUT}/result.txt`,
176+
'deterministic-output-path': `${workerEnv.IEXEC_OUT}/result.json`,
177177
},
178178
null,
179179
2
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
{"deterministic-output-path":"./tests/_test_outputs_/iexec_out/result.txt"}
1+
{
2+
"deterministic-output-path": "./tests/_test_outputs_/iexec_out/result.json"
3+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"message": "Bulk processing completed: 1 successful, 1 failed",
3+
"total-count": 2,
4+
"success-count": 1,
5+
"error-count": 1,
6+
"results": [
7+
{
8+
"index": 1,
9+
"protected-data": "data-chatId.zip",
10+
"response": {
11+
"message": "Your telegram message has been sent successfully.",
12+
"status": 200
13+
}
14+
},
15+
{
16+
"index": 2,
17+
"protected-data": "invalid-data.zip",
18+
"response": {
19+
"status": 500,
20+
"message": "Failed to process protected-data 2. Cause: Failed to parse ProtectedData 2: Failed to load protected data"
21+
}
22+
}
23+
]
24+
}

dapp/tests/_test_outputs_/iexec_out/result.txt

Lines changed: 0 additions & 4 deletions
This file was deleted.

dapp/tests/e2e/app.test.js

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ describe('sendTelegram', () => {
153153

154154
const { IEXEC_OUT } = process.env;
155155
const resultTxt = await fsPromises.readFile(
156-
path.join(IEXEC_OUT, 'result.txt'),
156+
path.join(IEXEC_OUT, 'result.json'),
157157
'utf-8'
158158
);
159159
const computedJson = await fsPromises.readFile(
@@ -165,7 +165,7 @@ describe('sendTelegram', () => {
165165
expect(result.message).toBe('Failed to send Telegram message.');
166166
expect(result.status).toBe(404);
167167
expect(JSON.parse(computedJson)).toStrictEqual({
168-
'deterministic-output-path': `${IEXEC_OUT}/result.txt`,
168+
'deterministic-output-path': `${IEXEC_OUT}/result.json`,
169169
});
170170
});
171171

@@ -174,7 +174,7 @@ describe('sendTelegram', () => {
174174

175175
const { IEXEC_OUT } = process.env;
176176
const resultTxt = await fsPromises.readFile(
177-
path.join(IEXEC_OUT, 'result.txt'),
177+
path.join(IEXEC_OUT, 'result.json'),
178178
'utf-8'
179179
);
180180
const computedJson = await fsPromises.readFile(
@@ -188,7 +188,7 @@ describe('sendTelegram', () => {
188188
);
189189
expect(result.status).toBe(200);
190190
expect(JSON.parse(computedJson)).toStrictEqual({
191-
'deterministic-output-path': `${IEXEC_OUT}/result.txt`,
191+
'deterministic-output-path': `${IEXEC_OUT}/result.json`,
192192
});
193193
});
194194

@@ -206,11 +206,11 @@ describe('sendTelegram', () => {
206206
const { IEXEC_OUT } = process.env;
207207

208208
// Check individual result files are NOT created for bulk processing
209-
// Only result.txt and computed.json should exist
209+
// Only result.json and computed.json should exist
210210

211-
// Check result.txt (main output file)
211+
// Check result.json (main output file)
212212
const resultTxt = await fsPromises.readFile(
213-
path.join(IEXEC_OUT, 'result.txt'),
213+
path.join(IEXEC_OUT, 'result.json'),
214214
'utf-8'
215215
);
216216

@@ -223,15 +223,15 @@ describe('sendTelegram', () => {
223223
results: [
224224
{
225225
index: 1,
226-
dataset: 'data-chatId.zip',
226+
'protected-data': 'data-chatId.zip',
227227
response: {
228228
message: 'Your telegram message has been sent successfully.',
229229
status: 200,
230230
},
231231
},
232232
{
233233
index: 2,
234-
dataset: 'data-chatId.zip',
234+
'protected-data': 'data-chatId.zip',
235235
response: {
236236
message: 'Your telegram message has been sent successfully.',
237237
status: 200,
@@ -248,7 +248,7 @@ describe('sendTelegram', () => {
248248

249249
const computed = JSON.parse(computedJson);
250250
expect(computed).toStrictEqual({
251-
'deterministic-output-path': `${IEXEC_OUT}/result.txt`,
251+
'deterministic-output-path': `${IEXEC_OUT}/result.json`,
252252
});
253253
});
254254

@@ -260,9 +260,9 @@ describe('sendTelegram', () => {
260260

261261
const { IEXEC_OUT } = process.env;
262262

263-
// Check result.txt (main output file)
263+
// Check result.json (main output file)
264264
const resultTxt = await fsPromises.readFile(
265-
path.join(IEXEC_OUT, 'result.txt'),
265+
path.join(IEXEC_OUT, 'result.json'),
266266
'utf-8'
267267
);
268268

@@ -275,18 +275,20 @@ describe('sendTelegram', () => {
275275
results: [
276276
{
277277
index: 1,
278-
dataset: 'data-chatId.zip',
278+
'protected-data': 'data-chatId.zip',
279279
response: {
280280
message: 'Your telegram message has been sent successfully.',
281281
status: 200,
282282
},
283283
},
284284
{
285285
index: 2,
286-
dataset: 'invalid-data.zip',
286+
'protected-data': 'invalid-data.zip',
287287
response: {
288288
status: 500,
289-
message: expect.stringContaining('Failed to process dataset 2'),
289+
message: expect.stringContaining(
290+
'Failed to process protected-data 2. Cause:'
291+
),
290292
},
291293
},
292294
],
@@ -300,7 +302,7 @@ describe('sendTelegram', () => {
300302

301303
const computed = JSON.parse(computedJson);
302304
expect(computed).toStrictEqual({
303-
'deterministic-output-path': `${IEXEC_OUT}/result.txt`,
305+
'deterministic-output-path': `${IEXEC_OUT}/result.json`,
304306
});
305307
});
306308
});

dapp/tests/unit/sendTelegram.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ describe('start function', () => {
9393
});
9494

9595
expect(fs.writeFile).toHaveBeenCalledWith(
96-
'/mock/output/result.txt',
96+
'/mock/output/result.json',
9797
JSON.stringify(
9898
{
9999
message: 'Your telegram message has been sent successfully.',
@@ -106,7 +106,7 @@ describe('start function', () => {
106106
expect(fs.writeFile).toHaveBeenCalledWith(
107107
'/mock/output/computed.json',
108108
JSON.stringify(
109-
{ 'deterministic-output-path': '/mock/output/result.txt' },
109+
{ 'deterministic-output-path': '/mock/output/result.json' },
110110
null,
111111
2
112112
)

0 commit comments

Comments
 (0)